Exemplo n.º 1
0
 public function savedocOnClick($sender)
 {
     $store = Store::load($this->docform->store->getValue());
     if ($store == false) {
         $this->setError("Не  выбран  магазин");
         return;
     }
     $this->_doc->document_number = $this->docform->document_number->getText();
     $this->_doc->document_date = $this->docform->document_date->getDate();
     $this->_doc->headerdata['store_id'] = $store->store_id;
     $this->_doc->headerdata['storename'] = $store->storename;
     $isEdited = $this->_doc->document_id > 0;
     $conn = \ZCL\DB\DB::getConnect();
     $conn->BeginTrans();
     try {
         $this->_doc->save();
         if ($sender->id == 'execdoc') {
             $this->_doc->updateStatus(Document::STATE_EXECUTED);
         } else {
             $this->_doc->updateStatus($isEdited ? Document::STATE_EDITED : Document::STATE_NEW);
         }
         $conn->CommitTrans();
         App::RedirectBack();
     } catch (\ZippyERP\System\Exception $ee) {
         $conn->RollbackTrans();
         $this->setError($ee->message);
     } catch (\Exception $ee) {
         $conn->RollbackTrans();
         throw new \Exception($ee->message);
     }
 }
Exemplo n.º 2
0
 public function storedeleteOnClick($sender)
 {
     try {
         $b = Store::delete($sender->owner->getDataItem()->store_id);
     } catch (\Exception $e) {
         $this->setError("Нельзя удалить этот  склад");
     }
     $this->storetable->storelist->Reload();
 }
Exemplo n.º 3
0
 public function __construct($docid = 0, $basedocid = 0)
 {
     parent::__construct();
     $this->add(new Form('docform'));
     $this->docform->add(new TextInput('document_number'));
     $this->docform->add(new Date('document_date'))->setDate(time());
     $this->docform->add(new DropDownChoice('store', Store::findArray("storename", "store_type = " . Store::STORE_TYPE_RET)))->setChangeHandler($this, 'OnChangeStore');
     $this->docform->add(new AutocompleteTextInput('customer'))->setAutocompleteHandler($this, "OnAutoContragent");
     $this->docform->add(new SubmitLink('addrow'))->setClickHandler($this, 'addrowOnClick');
     $this->docform->add(new SubmitButton('savedoc'))->setClickHandler($this, 'savedocOnClick');
     $this->docform->add(new SubmitButton('execdoc'))->setClickHandler($this, 'savedocOnClick');
     $this->docform->add(new Button('backtolist'))->setClickHandler($this, 'backtolistOnClick');
     $this->docform->add(new Label('totalnds'));
     $this->docform->add(new Label('total'));
     $this->add(new Form('editdetail'))->setVisible(false);
     $this->editdetail->add(new TextInput('editquantity'))->setText("1");
     $this->editdetail->add(new TextInput('editprice'));
     $this->editdetail->add(new AutocompleteTextInput('edittovar'))->setAutocompleteHandler($this, "OnAutoItem");
     $this->editdetail->edittovar->setChangeHandler($this, 'OnChangeItem');
     $this->editdetail->add(new Button('cancelrow'))->setClickHandler($this, 'cancelrowOnClick');
     $this->editdetail->add(new SubmitButton('submitrow'))->setClickHandler($this, 'saverowOnClick');
     if ($docid > 0) {
         //загружаем   содержимок  документа настраницу
         $this->_doc = Document::load($docid);
         $this->docform->document_number->setText($this->_doc->document_number);
         $this->docform->totalnds->setText(H::fm($this->_doc->headerdata['totalnds']));
         $this->docform->document_date->setDate($this->_doc->document_date);
         $this->docform->store->setValue($this->_doc->headerdata['store']);
         $this->docform->customer->setKey($this->_doc->headerdata['customer']);
         $this->docform->customer->setText($this->_doc->headerdata['customername']);
         foreach ($this->_doc->detaildata as $item) {
             $item = new Item($item);
             $this->_tovarlist[$item->item_id] = $item;
         }
     } else {
         $this->_doc = Document::create('ReturnRetailIssue');
         $this->docform->document_number->setText($this->_doc->nextNumber());
         if ($basedocid > 0) {
             //создание на  основании
             $basedoc = Document::load($basedocid);
             if ($basedoc instanceof Document) {
                 $this->_basedocid = $basedocid;
                 if ($basedoc->meta_name == 'RetailIssue') {
                     $this->docform->customer->setKey($basedoc->headerdata['customer']);
                     $this->docform->customer->setText($basedoc->headerdata['customername']);
                     foreach ($basedoc->detaildata as $_item) {
                         $item = new Item($_item);
                         $this->_tovarlist[$item->item_id] = $item;
                     }
                 }
             }
         }
     }
     $this->docform->add(new DataView('detail', new \Zippy\Html\DataList\ArrayDataSource(new \Zippy\Binding\PropertyBinding($this, '_tovarlist')), $this, 'detailOnRow'))->Reload();
 }
Exemplo n.º 4
0
 public function generateReport()
 {
     $header = array('date' => date('d.m.Y', $this->document_date), "from" => Store::load($this->headerdata["storefrom"])->storename, "to" => Store::load($this->headerdata["storeto"])->storename, "document_number" => $this->document_number);
     $reportgen = new \ZCL\RepGen\RepGen(_ROOT . 'templates/erp/printforms/moveitem.html', $header);
     $i = 1;
     $detail = array();
     foreach ($this->detaildata as $value) {
         $detail[] = array("no" => $i++, "item_name" => $value['itemname'], "measure" => $value['measure_name'], "price" => H::fm($value['price']), "quantity" => $value['quantity'] / 1000);
     }
     $report = new \ZippyERP\ERP\Report('movebackitem.tpl');
     $html = $report->generate($header, $detail);
     return $html;
 }
Exemplo n.º 5
0
 public function Execute()
 {
     $cash = MoneyFund::getCash();
     $ret = "";
     $optype = $this->headerdata['optype'];
     if ($optype == self::TYPEOP_CUSTOMER) {
         $ret = Entry::AddEntry(30, 36, $this->headerdata['amount'], $this->document_id, $this->document_date);
         $sc = new SubConto($this, 36, 0 - $this->headerdata['amount']);
         $sc->setCustomer($this->headerdata['opdetail']);
         $sc->save();
     }
     if ($optype == self::TYPEOP_CASH) {
         $ret = Entry::AddEntry(30, 372, $this->headerdata['amount'], $this->document_id, $this->document_date);
         $sc = new SubConto($this, 372, 0 - $this->headerdata['amount']);
         $sc->setEmployee($this->headerdata['opdetail']);
         $sc->save();
     }
     if ($optype == self::TYPEOP_BANK) {
         $ret = Entry::AddEntry(30, 31, $this->headerdata['amount'], $this->document_id, $this->document_date);
         $sc = new SubConto($this, 31, 0 - $this->headerdata['amount']);
         $sc->setMoneyfund($this->headerdata['opdetail']);
         $sc->save();
     }
     if ($optype == self::TYPEOP_RET) {
         $store_id = $this->headerdata['opdetail'];
         // магазин
         $ret = Entry::AddEntry(30, 702, $this->headerdata['amount'], $this->document_id, $this->document_date);
         $sc = new SubConto($this, 702, 0 - $this->headerdata['amount']);
         $sc->setExtCode($this->headerdata['opdetail']);
         $sc->save();
         $store = \ZippyERP\ERP\Entity\Store::load($store_id);
         if ($store->store_type == \ZippyERP\ERP\Entity\Store::STORE_TYPE_RET_SUM) {
             $nds = \ZippyERP\ERP\Helper::nds(true);
             Entry::AddEntry(702, 643, $nds * $this->headerdata['amount'], $this->document_id, $this->document_date);
         }
     }
     //касса
     $sc = new SubConto($this, 30, $this->headerdata['amount']);
     $sc->setMoneyfund($cash->id);
     $sc->save();
     if (strlen($ret) > 0) {
         throw new \Exception($ret);
     }
     return true;
 }
Exemplo n.º 6
0
 private function generateReport()
 {
     $store = $this->filter->store->getValue();
     $item = $this->filter->item->getKey();
     $from = $this->filter->from->getDate();
     $to = $this->filter->to->getDate();
     $header = array('datefrom' => date('d.m.Y', $from), 'dateto' => date('d.m.Y', $to), "store" => Store::load($store)->storename, "item" => Item::load($item)->itemname, "measure" => Item::load($item)->measure_name);
     $i = 1;
     $detail = array();
     $conn = \ZCL\DB\DB::getConnect();
     $sql = "\n            SELECT\n              t.*,\n              (SELECT\n                  COALESCE(SUM(u.`quantity`), 0)\n                FROM erp_account_subconto u\n                WHERE u.`document_date` < t.dt\n                AND u.`stock_id` = t.`stock_id`) AS begin_quantity\n            FROM (\n            SELECT\n                st.stock_id,\n                price,\n                DATE(sc.document_date) AS dt,\n                SUM(\n                CASE WHEN quantity > 0 THEN quantity ELSE 0 END) AS obin,\n                SUM(\n                CASE WHEN quantity < 0 THEN 0 - quantity ELSE 0 END) AS obout,\n                GROUP_CONCAT(dc.document_number) AS docs\n              FROM\n               erp_account_subconto  sc join erp_store_stock  st on  sc.stock_id = st.stock_id\n               join erp_document  dc  on sc.document_id = dc.document_id\n\n              WHERE st.item_id = {$item}\n              AND st.store_id = {$store}\n              AND DATE(sc.document_date) >= " . $conn->DBDate($from) . "\n              AND DATE(sc.document_date) <= " . $conn->DBDate($to) . "\n              GROUP BY st.stock_id,\n                       st.price,\n                       DATE(sc.document_date)) t\n            ORDER BY dt\n        ";
     $rs = $conn->Execute($sql);
     foreach ($rs as $row) {
         $detail[] = array("no" => $i++, "date" => date("d.m.Y", strtotime($row['dt'])), "documents" => str_replace(',', '<br>', $row['docs']), "price" => H::fm($row['price']), "in" => $row['begin_quantity'] / 1000, "obin" => $row['obin'] / 1000, "obout" => $row['obout'] / 1000, "out" => ($row['begin_quantity'] + $row['obin'] - $row['obout']) / 1000);
     }
     $report = new \ZippyERP\ERP\Report('itemactivity.tpl');
     $html = $report->generate($header, $detail);
     return $html;
 }
Exemplo n.º 7
0
 public function additembtnOnClick($sender)
 {
     $id = $this->docform->e_itemlist->getKey();
     if (isset($this->_itemarr[$id])) {
         $this->setError('Дублирование строки');
         return;
     }
     if ($id == 0) {
         $this->setError('Не выбран  ТМЦ');
         return;
     }
     $item = Item::load($id);
     $item->op = $this->docform->e_itemop->getValue();
     if ($item->op == 0) {
         $this->setError('Не выбран  счет');
         return;
     }
     $item->store_id = $this->docform->e_storelist->getValue();
     if ($item->store_id == 0) {
         $this->setError('Не выбран склад');
         return;
     }
     $store = Store::load($item->store_id);
     $item->store_name = $store->storename;
     $item->qty = 1000 * $this->docform->e_quantity->getText();
     // $item->partion = 100 * $this->docform->e_price->getText();
     $item->price = 100 * $this->docform->e_price->getText();
     if ($item->price == 0) {
         $this->setError('Введите  цену');
         return;
     }
     if (strpos($item->op, '_c') > 0) {
         $stock = \ZippyERP\ERP\Entity\Stock::getStock($item->store_id, $id, $item->price, false);
         if ($stock == null) {
             $this->setError("Не найдена  партия " . H::fm($item->price));
             return;
         }
     }
     $this->_itemarr[$id] = $item;
     $this->docform->itemtable->Reload();
     $this->docform->e_quantity->setText('1');
     $this->docform->e_price->setText('0');
 }
Exemplo n.º 8
0
 public function __construct($docid = 0, $basedocid = 0)
 {
     parent::__construct();
     $this->add(new Form('docform'));
     $this->docform->add(new TextInput('document_number'));
     $this->docform->add(new Date('document_date'))->setDate(time());
     $this->docform->add(new DropDownChoice('store', Store::findArray("storename", "store_type = " . Store::STORE_TYPE_OPT)))->setChangeHandler($this, 'OnChangeStore');
     $this->docform->add(new AutocompleteTextInput('customer'))->setAutocompleteHandler($this, "OnAutoContragent");
     $this->docform->add(new CheckBox('isnds', true))->setChangeHandler($this, 'onIsnds');
     $this->docform->add(new CheckBox('cash'));
     $this->docform->add(new AutocompleteTextInput('contract'))->setAutocompleteHandler($this, "OnAutoContract");
     $this->docform->add(new SubmitLink('addrow'))->setClickHandler($this, 'addrowOnClick');
     $this->docform->add(new SubmitButton('savedoc'))->setClickHandler($this, 'savedocOnClick');
     $this->docform->add(new SubmitButton('execdoc'))->setClickHandler($this, 'savedocOnClick');
     $this->docform->add(new Button('backtolist'))->setClickHandler($this, 'backtolistOnClick');
     $this->docform->add(new Label('total'));
     $this->docform->add(new Label('totalnds'));
     $this->add(new Form('editdetail'))->setVisible(false);
     $this->editdetail->add(new TextInput('editquantity'))->setText("1");
     $this->editdetail->add(new TextInput('editprice'));
     $this->editdetail->add(new TextInput('editpricends'));
     $this->editdetail->add(new AutocompleteTextInput('edittovar'))->setAutocompleteHandler($this, "OnAutoItem");
     $this->editdetail->edittovar->setChangeHandler($this, 'OnChangeItem');
     $this->editdetail->add(new DropDownChoice('edittype', $this->_itemtype))->setChangeHandler($this, "OnItemType");
     $this->editdetail->add(new Label('qtystock'));
     $this->editdetail->add(new Button('cancelrow'))->setClickHandler($this, 'cancelrowOnClick');
     $this->editdetail->add(new SubmitButton('submitrow'))->setClickHandler($this, 'saverowOnClick');
     if ($docid > 0) {
         //загружаем   содержимок  документа настраницу
         $this->_doc = Document::load($docid);
         $this->docform->document_number->setText($this->_doc->document_number);
         //  $this->docform->nds->setText($this->_doc->headerdata['nds'] / 100);
         $this->docform->document_date->setDate($this->_doc->document_date);
         $this->docform->store->setValue($this->_doc->headerdata['store']);
         $this->docform->isnds->setChecked($this->_doc->headerdata['isnds']);
         $this->docform->cash->setChecked($this->_doc->headerdata['cash']);
         $this->docform->customer->setKey($this->_doc->headerdata['customer']);
         $this->docform->customer->setText($this->_doc->headerdata['customername']);
         $this->docform->contract->setKey($this->_doc->headerdata['contract']);
         $this->docform->contract->setText($this->_doc->headerdata['contractnumber']);
         foreach ($this->_doc->detaildata as $item) {
             $stock = new Stock($item);
             $this->_tovarlist[$stock->stock_id] = $stock;
         }
     } else {
         $this->_doc = Document::create('GoodsIssue');
         $this->docform->document_number->setText($this->_doc->nextNumber());
         if ($basedocid > 0) {
             //создание на  основании
             $basedoc = Document::load($basedocid);
             if ($basedoc instanceof Document) {
                 $this->_basedocid = $basedocid;
                 $this->docform->based->setText($basedoc->meta_desc . " №" . $basedoc->document_number);
                 if ($basedoc->meta_name == 'Invoice') {
                     $this->docform->customer->setKey($basedoc->headerdata['customer']);
                     $this->docform->customer->setText($basedoc->headerdata['customername']);
                     $this->docform->contract->setKey($basedoc->headerdata['contract']);
                     $this->docform->contract->setText($basedoc->headerdata['contractnumber']);
                     $this->docform->isnds->setChecked($basedoc->headerdata['isnds']);
                     foreach ($basedoc->detaildata as $item) {
                         $item = new Item($item);
                         //находим  последнюю партию по  первому складу
                         $options = $this->docform->store->getOptionList();
                         $keys = array_keys($options);
                         $stock = Stock::getFirst("closed <> 1 and group_id={$item->group_id} and item_id={$item->item_id} and store_id=" . $keys[0], 'stock_id', 'desc');
                         if ($stock instanceof Stock) {
                             $stock->quantity = $item->quantity;
                             //  $stock->partion = $item->priceopt;
                             //   $stock->group_id = $item->group_id;
                             $stock->pricends = $item->pricends;
                             $stock->price = $item->price;
                             $this->_tovarlist[$stock->stock_id] = $stock;
                         } else {
                             $this->setError('Не найден на складе  товар ' . $item->itemname);
                         }
                     }
                 }
             }
         }
     }
     $this->docform->add(new DataView('detail', new \Zippy\Html\DataList\ArrayDataSource(new \Zippy\Binding\PropertyBinding($this, '_tovarlist')), $this, 'detailOnRow'))->Reload();
 }
Exemplo n.º 9
0
 public function OnChangeItem($sender)
 {
     $stock_id = $sender->getKey();
     $stock = Stock::load($stock_id);
     $store = Store::load($this->docform->storeto->getValue());
     if ($store->store_type == Store::STORE_TYPE_OPT) {
     } else {
         $item = Item::load($stock->item_id);
     }
     if ($store->store_type == Store::STORE_TYPE_RET) {
     }
 }
Exemplo n.º 10
0
 public function savedocOnClick($sender)
 {
     if ($this->checkForm() == false) {
         return;
     }
     $store = Store::load($this->docform->store->getValue());
     $this->_doc->headerdata = array('store' => $store->store_id, 'storename' => $store->storename);
     $this->_doc->detaildata = array();
     foreach ($this->_itemlist as $item) {
         $this->_doc->detaildata[] = $item->getData();
     }
     $this->_doc->document_number = $this->docform->document_number->getText();
     $this->_doc->document_date = strtotime($this->docform->document_date->getText());
     $isEdited = $this->_doc->document_id > 0;
     $conn = \ZCL\DB\DB::getConnect();
     $conn->BeginTrans();
     try {
         $this->_doc->save();
         if ($sender->id == 'execdoc') {
             $this->_doc->updateStatus(Document::STATE_EXECUTED);
         } else {
             $this->_doc->updateStatus($isEdited ? Document::STATE_EDITED : Document::STATE_NEW);
         }
         $conn->CommitTrans();
         App::RedirectBack();
     } catch (\ZippyERP\System\Exception $ee) {
         $conn->RollbackTrans();
         $this->setError($ee->message);
     } catch (\Exception $ee) {
         $conn->RollbackTrans();
         throw new \Exception($ee->message);
     }
 }
Exemplo n.º 11
0
 public function beforeRender()
 {
     parent::beforeRender();
     $store = Store::load($this->docform->storeto->getValue());
     if ($store->store_type == Store::STORE_TYPE_OPT) {
         $this->editdetail->editprice->setVisible(false);
     } else {
         $this->editdetail->editprice->setVisible(true);
     }
 }
Exemplo n.º 12
0
 public function opdetailOnAutocomplete($sender)
 {
     $text = $sender->getValue();
     $optype = $this->docform->optype->getValue();
     if ($optype == CRIN::TYPEOP_CUSTOMER) {
         return Customer::findArray('customer_name', "customer_name like '%{$text}%' and ( cust_type=" . Customer::TYPE_BUYER . " or cust_type= " . Customer::TYPE_BUYER_SELLER . " )");
     }
     if ($optype == CRIN::TYPEOP_BANK) {
         return MoneyFund::findArray('title', "title like '%{$text}%' ");
     }
     if ($optype == CRIN::TYPEOP_CASH) {
         return Employee::findArray('fullname', "fullname like '%{$text}%' ");
     }
     if ($optype == CRIN::TYPEOP_RET) {
         return Store::findArray('storename', "storename like '%{$text}%' and (store_type = " . Store::STORE_TYPE_RET . ' or store_type=' . Store::STORE_TYPE_RET_SUM . ") ");
     }
 }
Exemplo n.º 13
0
 public function __construct($docid = 0, $basedocid = 0)
 {
     parent::__construct();
     $this->add(new Form('docform'));
     $this->docform->add(new TextInput('document_number'));
     $this->docform->add(new Date('document_date'))->setDate(time());
     $this->docform->add(new DropDownChoice('employee', Employee::findArray('shortname')));
     $this->docform->add(new DropDownChoice('store', Store::findArray("storename", "store_type=" . Store::STORE_TYPE_OPT)));
     $this->docform->add(new DropDownChoice('expensetype', \ZippyERP\ERP\Entity\Doc\ExpenseReport::expenceList()))->setChangeHandler($this, 'OnExpenseList');
     $this->docform->add(new TextInput('expenseamount'))->setVisible(false);
     $this->docform->add(new CheckBox('isnds'))->setChangeHandler($this, 'onIsnds');
     $this->docform->add(new SubmitLink('addrow'))->setClickHandler($this, 'addrowOnClick');
     $this->docform->add(new Button('backtolist'))->setClickHandler($this, 'backtolistOnClick');
     $this->docform->add(new SubmitButton('savedoc'))->setClickHandler($this, 'savedocOnClick');
     $this->docform->add(new SubmitButton('execdoc'))->setClickHandler($this, 'savedocOnClick');
     $this->docform->add(new Label('totalnds'));
     $this->docform->add(new Label('total'));
     $this->add(new Form('editdetail'))->setVisible(false);
     $this->editdetail->add(new AutocompleteTextInput('edititem'))->setAutocompleteHandler($this, 'OnAutoItem');
     $this->editdetail->add(new TextInput('editquantity'))->setText("1");
     $this->editdetail->add(new TextInput('editprice'));
     $this->editdetail->add(new TextInput('editpricends'));
     $this->editdetail->add(new Button('cancelrow'))->setClickHandler($this, 'cancelrowOnClick');
     $this->editdetail->add(new SubmitButton('saverow'))->setClickHandler($this, 'saverowOnClick');
     // $this->editdetail->add(new SubmitLink('additem'))->setClickHandler($this, 'addItemOnClick');
     if ($docid > 0) {
         //загружаем   содержимок  документа настраницу
         $this->_doc = Document::load($docid);
         $this->docform->document_number->setText($this->_doc->document_number);
         $this->docform->expenseamount->setText(H::fm($this->_doc->headerdata['expenseamount']));
         $this->docform->isnds->setChecked($this->_doc->headerdata['isnds']);
         $this->docform->document_date->setDate($this->_doc->document_date);
         $this->docform->employee->setValue($this->_doc->headerdata['employee']);
         $this->docform->store->setValue($this->_doc->headerdata['store']);
         $this->docform->expensetype->setValue($this->_doc->headerdata['expensetype']);
         foreach ($this->_doc->detaildata as $item) {
             $item = new Item($item);
             $this->_itemlist[$item->item_id] = $item;
         }
         $val = $this->_doc->headerdata['expensetype'];
         if ($val == 201 || $val == 22 || $val == 281) {
             $this->docform->expenseamount->setVisible(false);
             $this->docform->store->setVisible(true);
             $this->docform->addrow->setVisible(true);
         } else {
             $this->docform->expenseamount->setVisible(true);
             $this->docform->store->setVisible(false);
             $this->docform->addrow->setVisible(false);
         }
     } else {
         $this->_doc = Document::create('ExpenseReport');
         /* if ($basedocid > 0) {  //создание на  основании
                       $basedoc = Document::load($basedocid);
                       if ($basedoc instanceof Document) {
                       $this->_basedocid = $basedocid;
         
         
                       /*
                       if ($basedoc->meta_name == 'PurchaseInvoice') {
                       $this->docform->isnds->setChecked($basedoc->headerdata['isnds']);
                       $this->docform->employee->setValue($basedoc->headerdata['employee']);
         
                       foreach ($basedoc->detaildata as $_item) {
                       $item = new Item($_item);
                       $this->_itemlist[$item->item_id] = $item;
                       }
                       }
                       }
                       } */
     }
     $this->docform->add(new DataView('detail', new \Zippy\Html\DataList\ArrayDataSource(new \Zippy\Binding\PropertyBinding($this, '_itemlist')), $this, 'detailOnRow'))->Reload();
     $this->add(new \ZippyERP\ERP\Blocks\Item('itemdetail', $this, 'OnItem'))->setVisible(false);
 }