Ejemplo n.º 1
1
 public function Execute()
 {
     $conn = \ZCL\DB\DB::getConnect();
     $store_id = $this->headerdata['store_id'];
     $item = \ZippyERP\ERP\Entity\Item::getSumItem();
     $stock = \ZippyERP\ERP\Entity\Stock::getStock($store_id, $item->item_id, 1, true);
     $discont = 0;
     //скидки  704  счет
     $date = new Carbon();
     $date->setTimestamp($this->document_date);
     $end = $date->endOfMonth()->getTimestamp();
     $begin = $date->startOfMonth()->getTimestamp();
     $sql = " select coalesce(abs(sum(amount)),0) from erp_account_subconto where amount < 0  and account_id=285 and  extcode  = {$store_id} and  document_date  <= " . $conn->DBDate($end);
     $tm = $conn->GetOne($sql);
     //торговая  наценка на  конец периода
     //остатки на  конец периода
     $sql = " select coalesce(sum(quantity),0) AS quantity,coalesce(price,0) as price  from erp_account_subconto sc join erp_store_stock  st on sc.stock_id = st.stock_id where    store_id = {$store_id} and date(document_date) <= " . $conn->DBDate($end);
     $row = $conn->GetRow($sql);
     $ost = $row['quantity'] / 1000;
     $ost = $ost * $row['price'];
     if ($ost == 0) {
         return;
     }
     //выручка
     $sql = " select coalesce(abs(sum(amount)),0) from erp_account_subconto where amount < 0  and account_id=702 and  extcode  = {$store_id} and date(document_date) <= " . $conn->DBDate($end) . " and date(document_date) >= " . $conn->DBDate($begin);
     $saled = $conn->GetOne($sql);
     //выручка сданная в кассу
     $k = ($tm - $discont) / ($ost - $discont);
     $sb = (1 - $k) * $saled;
     //себестоимость
     // списываем  наценку
     Entry::AddEntry("285", "282", $saled - $sb, $this->document_id, $this->document_date);
     // себестоимость реализации
     Entry::AddEntry("902", "282", $sb, $this->document_id, $this->document_date);
     $item = \ZippyERP\ERP\Entity\Item::getSumItem();
     $stockto = \ZippyERP\ERP\Entity\Stock::getStock($store_id, $item->item_id, 1, true);
     $sc = new SubConto($this, 282, 0 - $saled);
     $sc->setStock($stockto->stock_id);
     $sc->setQuantity(0 - $saled * 1000);
     //цена  единицы  товара - 1 копейка.
     $sc->save();
     // НДС
     $nds = H::nds(true);
     Entry::AddEntry("702", "641", $saled * $nds, $this->document_id, $this->document_date);
     return true;
 }
Ejemplo n.º 2
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;
 }