Exemple #1
0
 public function Execute()
 {
     $conn = \ZCL\DB\DB::getConnect();
     $conn->StartTrans();
     $ret = 0;
     // торговая  наценка
     $amount = 0;
     foreach ($this->detaildata as $value) {
         //приниммаем на склад
         $stockto = Stock::getStock($this->headerdata['storeto'], $value['item_id'], $value['partion'], true);
         $sc = new SubConto($this, $value['type'], $value['quantity'] / 1000 * $stockto->price);
         $sc->setStock($stockto->stock_id);
         $sc->setQuantity($value['quantity']);
         $sc->save();
         $store = Store::load($this->headerdata['storefrom']);
         if ($store->store_type == Store::STORE_TYPE_RET) {
             //розница
             $stockfrom = Stock::getFirst("store_id={$this->headerdata['storefrom']} and item_id={$value['item_id']} and price={$value['price']} and partion={$value['partion']} and closed <> 1");
             if ($stockfrom == null) {
                 return false;
             }
             $sc = new SubConto($this, 282, 0 - $value['quantity'] / 1000 * $stockfrom->price);
             $sc->setStock($stockfrom->stock_id);
             $sc->setQuantity(0 - $value['quantity']);
             $sc->save();
             $ret += $value['quantity'] / 1000 * ($value['price'] - $value['partion']);
             $amount += $value['quantity'] / 1000 * $value['partion'];
         }
         if ($store->store_type == Store::STORE_TYPE_RET_SUM) {
             //розница суммовой учет
             //специальный  товар  для  cуммового  учета
             $item = \ZippyERP\ERP\Entity\Item::getSumItem();
             $stockfrom = Stock::getStock($this->headerdata['storefrom'], $item->item_id, 1, true);
             $sc = new SubConto($this, 282, 0 - $value['quantity'] * $value['price']);
             //цена  единицы  товара = 1 копейка.
             $sc->setStock($stockfrom->stock_id);
             $sc->setQuantity(0 - $value['quantity'] * $value['price']);
             //цена  единицы  товара - 1 копейка.
             $sc->save();
             $ret += $value['quantity'] / 1000 * ($value['price'] - $value['partion']);
             $amount += $value['quantity'] / 1000 * $value['partion'];
         }
     }
     if ($amount > 0) {
         // розница
         Entry::AddEntry(281, 282, $amount, $this->document_id, $this->document_date);
         Entry::AddEntry(285, 282, $ret, $this->document_id, $this->document_date);
         $sc = new SubConto($this, 285, $ret);
         $sc->setExtCode($store->store_id);
         $sc->save();
     }
     $conn->CompleteTrans();
     return true;
 }
Exemple #2
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();
 }
Exemple #3
0
 public function saverowOnClick($sender)
 {
     $id = $this->editdetail->edititem->getKey();
     if ($id == 0) {
         $this->setError("Не выбран ТМЦ");
         return;
     }
     $stock = Stock::load($id);
     $stock->quantity = 1000 * $this->editdetail->editquantity->getText();
     $stock->price = 100 * $this->editdetail->editprice->getText();
     $stock->type = $this->editdetail->edittype->getValue();
     $doc = Document::getFirst("meta_name ='MoveItem' and  state=" . Document::STATE_EXECUTED . "  and content  like '%<item_id>{$stock->item_id}</item_id>%'");
     if ($doc == null) {
         $this->setWarn('Не найден документ перемещения со склада  с таким  ТМЦ');
     }
     $store = Store::load($this->docform->storefrom->getValue());
     // $fromstock = Stock::getStock($this->docform->storefrom->getValue(),$stock->item_id,$stock->price,false);
     $stockfrom = Stock::getFirst("store_id={$store->store_id} and item_id={$stock->item_id} and price={$stock->price} and partion={$stock->partion} and closed <> 1");
     if ($stockfrom == null && $store->store_type == Store::STORE_TYPE_RET) {
         $this->setError('Товар  с  такой  ценой и партией не найден  в  магазине');
         return;
     }
     $this->_itemlist[$stock->stock_id] = $stock;
     $this->editdetail->setVisible(false);
     $this->docform->setVisible(true);
     $this->docform->detail->Reload();
     //очищаем  форму
     $this->editdetail->edititem->setKey(0);
     $this->editdetail->edititem->setText('');
     $this->editdetail->editquantity->setText("1");
     $this->editdetail->editprice->setText("");
 }
Exemple #4
0
 public function OnChangeItem($sender)
 {
     $stock_id = $sender->getKey();
     $stock = Stock::load($stock_id);
     $this->editdetail->qtystock->setText(Stock::getQuantity($stock_id, $this->docform->document_date->getDate(), $this->editdetail->edittype->getValue()) / 1000 . ' ' . $stock->measure_name);
     $store = Store::load($this->docform->storeto->getValue());
     if ($store->store_type == Store::STORE_TYPE_OPT) {
         // $this->editdetail->editprice->setText(H::fm($stock->price));
     } else {
         $item = Item::load($stock->item_id);
         $this->editdetail->editprice->setText(H::fm($item->priceret));
     }
     if ($store->store_type == Store::STORE_TYPE_RET) {
         //если  уже   есть  товар  в  магазине  берем  цену  оттуда
         $stock = Stock::getFirst("store_id={$store->store_id} and item_id={$stock->item_id} and closed <> 1");
         if ($stock instanceof Stock) {
             $this->editdetail->editprice->setText(H::fm($stock->price));
         }
     }
 }