Skip to content

Commit

Permalink
Merge pull request #143 from leon-mbs/dev
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
leon-mbs authored Mar 16, 2021
2 parents a95472d + c6ceb89 commit 77cdf74
Show file tree
Hide file tree
Showing 27 changed files with 221 additions and 41 deletions.
34 changes: 33 additions & 1 deletion www/app/entity/doc/goodsissue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Entity\Doc;

use App\Entity\Entry;
use App\Entity\Item;
use App\Helper as H;

/**
Expand Down Expand Up @@ -85,14 +86,35 @@ public function generateReport() {
}

public function Execute() {
//$conn = \ZDB\DB::getConnect();

$k = 1; //учитываем скидку
if ($this->headerdata["paydisc"] > 0 && $this->amount > 0) {
$k = ($this->amount - $this->headerdata["paydisc"]) / $this->amount;
}
$amount = 0;
foreach ($this->unpackDetails('detaildata') as $item) {


//оприходуем с производства
if( $this->headerdata['fromprod'] ==1 && $item->item_type==Item::TYPE_PROD) {
$price = $item->getProdprice() ;

if($price ==0){
throw new \Exception(H::l('noselfprice',$item->itemname)) ;

}
$stock = \App\Entity\Stock::getStock($this->headerdata['store'], $item->item_id, $price, $item->snumber, $item->sdate, true);

$sc = new Entry($this->document_id, $item->quantity * $price, $item->quantity);
$sc->setStock($stock->stock_id);


$sc->save();

}


//продажа
$listst = \App\Entity\Stock::pickup($this->headerdata['store'], $item);

foreach ($listst as $st) {
Expand All @@ -102,8 +124,18 @@ public function Execute() {
$sc->save();
$amount += $item->price * $k * $st->quantity;
}




}







//списываем бонусы
if ($this->headerdata['paydisc'] > 0 && $this->customer_id > 0) {
$customer = \App\Entity\Customer::load($this->customer_id);
Expand Down
45 changes: 35 additions & 10 deletions www/app/entity/doc/prodreceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,45 @@ public function generateReport() {
public function Execute() {
$types = array();
$common = \App\System::getOptions("common");

//аналитика
$parts = array();


foreach ($this->unpackDetails('detaildata') as $item) {
$listst = \App\Entity\Stock::pickup($this->headerdata['store'], $item);

foreach ($listst as $st) {
$sc = new Entry($this->document_id, $st->quantity * $item->price, $st->quantity);
$sc->setStock($st->stock_id);
$sc->save();
}

$stock = \App\Entity\Stock::getStock($this->headerdata['store'], $item->item_id, $item->price, $item->snumber, $item->sdate, true);

}
$sc = new Entry($this->document_id, $item->quantity * $item->price, $item->quantity);
$sc->setStock($stock->stock_id);
// $sc->setExtCode($item->price); //Для АВС


$sc->save();


$set = \App\Entity\ItemSet::find("pitem_id=" . $item->item_id);
foreach($set as $part) {
if( isset($parts[$part->item_id])==false) $parts[$part->item_id] =0;
$parts[$part->item_id] += $part->qty;
}


}
// списываем в производство
if($this->headerdata['storefrom'] >0) {
foreach($parts as $id=>$qty) {
$item = \App\Entity\Item::load($id);
$item->quantity = $qty;
$listst = \App\Entity\Stock::pickup($this->headerdata['storefrom'], $item);

foreach ($listst as $st) {
$sc = new Entry($this->document_id, 0 - $st->quantity * $st->partion, 0 - $st->quantity);
$sc->setStock($st->stock_id);

$sc->save();
}

}
}
return true;
}

Expand Down
4 changes: 3 additions & 1 deletion www/app/entity/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ public function getProdprice(){
$price += ($iset->qty * $pr);
}
}

if($price==0) { //ищем последнюю партию
$pr = $this->getLastPartion(0);
}

return $price;
}
Expand Down
2 changes: 1 addition & 1 deletion www/app/entity/stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static function pickup($store_id, $item) {
$last = self::getFirst($where, ' stock_id desc ');
if ($last == null) {
$conn = \ZDB\DB::getConnect();
$lastpartion = $conn->GetOne("select coalesce(partion,0) from store_stock where qty > 0 and item_id={$item_id} order by stock_id desc limit 0,1 ") ;
$lastpartion = $conn->GetOne("select coalesce(partion,0) from store_stock where qty > 0 and item_id={$item->item_id} order by stock_id desc limit 0,1 ") ;
if($lastpartion==0) $lastpartion= $price;

$last = new Stock();
Expand Down
1 change: 1 addition & 0 deletions www/app/entity/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected function init() {
$this->user_id = 0;
$this->defstore = 0;
$this->defmf = 0;
$this->deffirm = 0;
$this->hidesidebar = 0;
$this->pagesize = 25;
$this->createdon = time();
Expand Down
24 changes: 23 additions & 1 deletion www/app/pages/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public function __construct($params = null) {
$this->_tvars["hidesidebar"] = $user->hidesidebar == 1 ? 'hold-transition sidebar-collapse' : 'hold-transition sidebar-mini sidebar-collapse';
//для скрытия блока разметки в шаблоне страниц
$this->_tvars["hideblock"] = false;


$this->generateTosats();

}

public function LogoutClick($sender) {
Expand Down Expand Up @@ -215,5 +219,23 @@ public function addJavaScript($js, $docready = false) {
public function goDocView() {
$this->goAnkor('dankor');
}


private function generateTosats() {

$this->_tvars["toasts"] = array();
if(\App\Session::getSession()->toasts == true) return;//уже показан

$user = System::getUser() ;
if($user->defstore ==0) {
$this->_tvars["toasts"][] = array('title'=>"title:\"".Helper::l("nodefstore")."\"") ;
}
if($user->deffirm ==0) {
$this->_tvars["toasts"][] = array('title'=>"title:\"".Helper::l("nodeffirm")."\"") ;
}
if($user->defmf ==0) {
$this->_tvars["toasts"][] = array('title'=>"title:\"".Helper::l("nodefmf")."\"") ;
}

\App\Session::getSession()->toasts = true;
}
}
24 changes: 22 additions & 2 deletions www/app/pages/doc/goodsissue.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Zippy\Html\Form\DropDownChoice;
use Zippy\Html\Form\Form;
use Zippy\Html\Form\SubmitButton;
use Zippy\Html\Form\CheckBox;
use Zippy\Html\Form\TextInput;
use Zippy\Html\Label;
use Zippy\Html\Link\ClickLink;
Expand Down Expand Up @@ -86,6 +87,7 @@ public function __construct($docid = 0, $basedocid = 0) {
$this->docform->add(new TextInput('order'));

$this->docform->add(new TextInput('notes'));
$this->docform->add(new CheckBox('fromprod'));

$cp = \App\Session::getSession()->clipboard;
$this->docform->add(new ClickLink('paste', $this, 'onPaste'))->setVisible(is_array($cp) && count($cp) > 0);
Expand Down Expand Up @@ -133,6 +135,7 @@ public function __construct($docid = 0, $basedocid = 0) {
$this->docform->total->setText($this->_doc->amount);

$this->docform->document_date->setDate($this->_doc->document_date);
$this->docform->fromprod->setChecked($this->_doc->headerdata['fromprod']);
$this->docform->payment->setValue($this->_doc->headerdata['payment']);

$this->docform->payamount->setText($this->_doc->payamount);
Expand Down Expand Up @@ -306,7 +309,7 @@ public function __construct($docid = 0, $basedocid = 0) {
$this->_tvars['manlist'][] = array('mitem' => $man);
}


$this->checkProd();
}

public function detailOnRow($row) {
Expand Down Expand Up @@ -347,7 +350,8 @@ public function deleteOnClick($sender) {
$this->docform->detail->Reload();
$this->calcTotal();
$this->calcPay();
}
$this->checkProd();
}

public function addrowOnClick($sender) {
$this->editdetail->setVisible(true);
Expand Down Expand Up @@ -544,6 +548,7 @@ public function saverowOnClick($sender) {
$this->editdetail->editserial->setText("");
$this->calcTotal();
$this->calcPay();
$this->checkProd();
}

public function cancelrowOnClick($sender) {
Expand Down Expand Up @@ -611,6 +616,7 @@ public function savedocOnClick($sender) {
$this->_doc->headerdata['store_name'] = $this->docform->store->getValueName();
$this->_doc->headerdata['pricetype'] = $this->docform->pricetype->getValue();
$this->_doc->headerdata['pricetypename'] = $this->docform->pricetype->getValueName();
$this->_doc->headerdata['fromprod'] = $this->docform->fromprod->isChecked() ?1:0;
$this->_doc->headerdata['order_id'] = $this->_orderid;

$this->_doc->packDetails('detaildata', $this->_itemlist);
Expand Down Expand Up @@ -1007,6 +1013,20 @@ public function onPaste($sender) {
$this->calcPay();
}

public function checkProd(){
$this->docform->fromprod->setVisible(false);
foreach ($this->_itemlist as $item) {
if($item->item_type == Item::TYPE_PROD) {
$this->docform->fromprod->setVisible(true);

return;
}

}


}

}


Expand Down
4 changes: 2 additions & 2 deletions www/app/pages/doc/ordercust.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public function detailOnRow($row) {
$row->add(new Label('desc', $item->desc));

$row->add(new Label('amount', H::fa($item->quantity * $item->price)));
$row->add(new ClickLink('edit'))->onClick($this, 'editOnClick');
$row->add(new SubmitLink('edit'))->onClick($this, 'editOnClick');
$row->edit->setVisible($item->old != true);

$row->add(new ClickLink('delete'))->onClick($this, 'deleteOnClick');
$row->add(new SubmitLink('delete'))->onClick($this, 'deleteOnClick');
}

public function editOnClick($sender) {
Expand Down
4 changes: 4 additions & 0 deletions www/app/pages/doc/prodreceipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct($docid = 0, $basedocid = 0) {
$this->docform->add(new Date('document_date'))->setDate(time());
$this->docform->add(new DropDownChoice('parea', \App\Entity\Prodarea::findArray("pa_name", ""), 0));
$this->docform->add(new DropDownChoice('store', Store::getList(), H::getDefStore()));
$this->docform->add(new DropDownChoice('storefrom', Store::getList(), H::getDefStore()));
$this->docform->add(new TextInput('notes'));


Expand Down Expand Up @@ -72,6 +73,7 @@ public function __construct($docid = 0, $basedocid = 0) {
$this->docform->parea->setValue($this->_doc->headerdata['parea']);

$this->docform->store->setValue($this->_doc->headerdata['store']);
$this->docform->storefrom->setValue($this->_doc->headerdata['storefrom']);

$this->_itemlist = $this->_doc->unpackDetails('detaildata');

Expand All @@ -84,6 +86,7 @@ public function __construct($docid = 0, $basedocid = 0) {
$this->_basedocid = $basedocid;
if ($basedoc->meta_name == 'ProdReceipt') {
$this->docform->store->setValue($basedoc->headerdata['store']);
$this->docform->storefrom->setValue($basedoc->headerdata['storefrom']);
$this->docform->parea->setValue($basedoc->headerdata['parea']);

$this->_itemlist = $basedoc->unpackDetails('detaildata');
Expand Down Expand Up @@ -264,6 +267,7 @@ public function savedocOnClick($sender) {
$this->_doc->headerdata['parea'] = $this->docform->parea->getValue();
$this->_doc->headerdata['pareaname'] = $this->docform->parea->getValueName();
$this->_doc->headerdata['store'] = $this->docform->store->getValue();
$this->_doc->headerdata['storefrom'] = $this->docform->storefrom->getValue();


$this->_doc->packDetails('detaildata', $this->_itemlist);
Expand Down
2 changes: 1 addition & 1 deletion www/app/pages/reference/itemlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function OnAutoSet($sender) {
}

$in .= ")";
return Item::findArray('itemname', "coalesce(item_type,0) <> 1 and coalesce(item_type,0) <>3 and item_id not in {$in} and (itemname like {$text} or item_code like {$text}) and disabled <> 1", 'itemname');
return Item::findArray('itemname', "coalesce(item_type,0) in (2,5) and item_id not in {$in} and (itemname like {$text} or item_code like {$text}) and disabled <> 1", 'itemname');
}

public function OnAddSet($sender) {
Expand Down
2 changes: 1 addition & 1 deletion www/app/pages/register/gilist.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function updateStatusButtons() {
$this->statuspan->statusform->closeorder->setVisible(false);
if ($this->_doc->headerdata['order_id'] > 0) {
$order = Document::load($this->_doc->headerdata['order_id']);
if ($order->payamount == $order->payed) {
if ($order->payamount == $order->payed || $order->headerdata['payment']==0) {
$this->statuspan->statusform->closeorder->setVisible(true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion www/app/pages/register/orderlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function updateStatusButtons() {

$this->statuspan->statusform->bttn->setVisible(true);
$this->statuspan->statusform->binv->setVisible(false);
$this->statuspan->statusform->bgi->setVisible(false);
$this->statuspan->statusform->bgi->setVisible(true);
$this->statuspan->statusform->btask->setVisible(false);

}
Expand Down
8 changes: 4 additions & 4 deletions www/app/pages/report/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private function generateReport() {
join `items` i on e.`item_id` = i.`item_id`
join `documents_view` d on d.`document_id` = e.`document_id`
where e.`item_id` >0 and e.`quantity` <>0
and d.`meta_name` in ('ProdIssue')
where e.`item_id` >0 and e.`quantity` < 0
and d.`meta_name` in ('ProdIssue','ProdReceipt')
{$wparea}
AND DATE(e.document_date) >= " . $conn->DBDate($from) . "
AND DATE(e.document_date) <= " . $conn->DBDate($to) . "
Expand All @@ -108,8 +108,8 @@ private function generateReport() {
join `items` i on e.`item_id` = i.`item_id`
join `documents_view` d on d.`document_id` = e.`document_id`
where e.`item_id` >0 and e.`quantity` <>0
and d.`meta_name` in ('ProdReceipt')
where e.`item_id` >0 and e.`quantity` >0
and d.`meta_name` in ('GoodsIssue','ProdIssue','ProdReceipt')
AND DATE(e.document_date) >= " . $conn->DBDate($from) . "
AND DATE(e.document_date) <= " . $conn->DBDate($to) . "
Expand Down
3 changes: 2 additions & 1 deletion www/app/pages/userlogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function onsubmit($sender) {
$user = Helper::login($login, $password);

if ($user instanceof User) {
\App\Session::getSession()->clean() ;
$user->lastlogin = time();
$user->save();
System::setUser($user);
Expand All @@ -96,7 +97,7 @@ public function onsubmit($sender) {

setcookie("remember", $user->user_id . '_' . md5($user->user_id . $_config['common']['salt']), time() + 60 * 60 * 24 * 30);
}
//$logger->info('Logined ' . $user->userlogin . ', ' . $_SERVER["REMOTE_ADDR"]);

if ($_config['modules']['shop'] == 1) {
App::Redirect('\App\Pages\Main');
} else {
Expand Down
5 changes: 5 additions & 0 deletions www/app/session.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public static function getSession() {
return $_SESSION['App_session'];
}

public function clean(){
$this->values = array();
$this->filter = array();

}
}
5 changes: 4 additions & 1 deletion www/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ body {
table {
font-family: "Arial"
}

.toast-header {

background-color: #fff;
}
Loading

0 comments on commit 77cdf74

Please sign in to comment.