示例#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;
 }
示例#2
0
 public function Execute()
 {
     $ret = 0;
     $cost = 0;
     foreach ($this->detaildata as $value) {
         $stock = \ZippyERP\ERP\Entity\Stock::load($value['stock_id']);
         $ret = $ret + $stock->price - $stock->partion;
         $cost = $cost + $stock->partion;
         $sc = new SubConto($this, 282, 0 - $value['quantity'] / 1000 * $stock->price);
         $sc->setStock($stock->stock_id);
         $sc->setQuantity(0 - $value['quantity']);
         $sc->save();
     }
     // списываем  наценку
     Entry::AddEntry("285", "282", $ret, $this->document_id, $this->document_date);
     $sc = new SubConto($this, 285, $ret);
     $sc->setExtCode($this->headerdata["store"]);
     $sc->save();
     // себестоимость реализации
     Entry::AddEntry("902", "282", $cost, $this->document_id, $this->document_date);
     //налоговые  обязательства
     if ($this->headerdata['totalnds'] > 0) {
         Entry::AddEntry("702", "643", $this->headerdata['totalnds'], $this->document_id, $this->document_date);
     }
     return true;
 }
示例#3
0
 public function Execute()
 {
     $conn = \ZCL\DB\DB::getConnect();
     $conn->StartTrans();
     $employee_id = $this->headerdata["employee"];
     $expensetype = $this->headerdata['expensetype'];
     if ($expensetype == 201 || $expensetype == 22 || $expensetype == 281) {
         foreach ($this->detaildata as $value) {
             //поиск  записи  о  товаре   на складе
             $stock = \ZippyERP\ERP\Entity\Stock::getStock($this->headerdata['store'], $value['item_id'], $value['price'], true);
             $sc = new SubConto($this, $expensetype, $value['quantity'] / 1000 * $stock->price);
             $sc->setStock($stock->stock_id);
             $sc->setQuantity($value['quantity']);
             $sc->save();
         }
         Entry::AddEntry($expensetype, "372", $this->headerdata['total'] - $this->headerdata['totalnds'], $this->document_id, $this->document_date);
         //налоговый кредит
         if ($this->headerdata['totalnds'] > 0) {
             Entry::AddEntry("644", "372", $this->headerdata['totalnds'], $this->document_id, $this->document_date);
         }
     } else {
         Entry::AddEntry($expensetype, "372", $this->headerdata["expenseamount"], $this->document_id, $this->document_date);
         $sc = new SubConto($this, 372, 0 - $this->headerdata["expenseamount"]);
         $sc->setEmployee($employee_id);
         $sc->save();
     }
     $conn->CompleteTrans();
     return true;
 }
示例#4
0
 public function Execute()
 {
     $conn = \ZCL\DB\DB::getConnect();
     $conn->StartTrans();
     $types = array();
     //аналитика
     foreach ($this->detaildata as $item) {
         $stock = \ZippyERP\ERP\Entity\Stock::getStock($this->headerdata['store'], $item['item_id'], $item['partion'], true);
         $sc = new SubConto($this, $item['type'], 0 - $item['partion'] * ($item['quantity'] / 1000));
         $sc->setStock($stock->stock_id);
         $sc->setQuantity(0 - $item['quantity']);
         $sc->save();
         //группируем по синтетическим счетам
         if ($types[$item['type']] > 0) {
             $types[$item['type']]['amount'] = $types[$item['type']] + $item['price'] * ($item['quantity'] / 1000);
             $types[$item['type']]['pamount'] = $types[$item['type']] + $item['partion'] * ($item['quantity'] / 1000);
             $types[$item['type']]['namount'] = $types[$item['type']] + $item['nds'];
         } else {
             $types[$item['type']]['amount'] = $item['pricends'] * ($item['quantity'] / 1000);
             $types[$item['type']]['pamount'] = $item['partion'] * ($item['quantity'] / 1000);
             $types[$item['type']]['namount'] = $item['nds'];
         }
     }
     foreach ($types as $acc => $value) {
         if ($acc == 281) {
             Entry::AddEntry("902", "281", $value['pamount'], $this->document_id, $this->document_date);
             Entry::AddEntry("36", "702", $value['amount'], $this->document_id, $this->document_date);
             if ($this->headerdata['isnds'] > 0) {
                 Entry::AddEntry("702", "643", $value['namount'], $this->document_id, $this->document_date);
             }
         }
         if ($acc == 26) {
             Entry::AddEntry("902", "26", $value['pamount'], $this->document_id, $this->document_date);
             Entry::AddEntry("36", "701", $value['amount'], $this->document_id, $this->document_date);
             if ($this->headerdata['isnds'] > 0) {
                 Entry::AddEntry("701", "643", $value['namount'], $this->document_id, $this->document_date);
             }
         }
         $sc = new SubConto($this, 36, $value['amount']);
         $sc->setCustomer($this->headerdata["customer"]);
         $sc->save();
     }
     if ($this->headerdata['cash'] == true) {
         $cash = MoneyFund::getCash();
         \ZippyERP\ERP\Entity\Entry::AddEntry("30", "36", $total, $this->document_id, $cash->id, $customer_id);
         $sc = new SubConto($this, 36, 0 - $total);
         $sc->setCustomer($this->headerdata["customer"]);
         $sc->save();
         $sc = new SubConto($this, 30, $total);
         $sc->setMoneyfund($cash->id);
         // $sc->save();
     }
     $conn->CompleteTrans();
     return true;
 }
示例#5
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;
 }
示例#6
0
 public function Execute()
 {
     $accarr = unserialize(base64_decode($this->headerdata['entry']));
     foreach ($accarr as $entry) {
         Entry::AddEntry($entry->acc_d, $entry->acc_c, $entry->amount, $this->document_id, $this->document_date);
     }
     //ТМЦ
     $itemarr = unserialize(base64_decode($this->headerdata['item']));
     if (is_array($itemarr)) {
         foreach ($itemarr as $item) {
             $stock = Stock::getStock($item->store_id, $item->item_id, $item->price, true);
             $acc = explode('_', $item->op);
             $sc = new SubConto($this, $acc[0], $acc[1] == 'd' ? $item->qty / 1000 * $stock->price : 0 - $item->qty / 1000 * $stock->price);
             $sc->setStock($stock->stock_id);
             $sc->setQuantity($acc[1] == 'd' ? $item->qty : 0 - $item->qty);
             $sc->save();
         }
     }
     //сотрудники (лицевые  счета)
     $emparr = unserialize(base64_decode($this->headerdata['emp']));
     if (count($emparr) > 0) {
         foreach ($emparr as $emp) {
             $val = $emp->val;
             $acc = explode('_', $emp->op);
             $sc = new SubConto($this, $acc[0], $acc[1] == 'd' ? $val : 0 - $val);
             $sc->setEmployee($emp->employee_id);
             $sc->save();
         }
     }
     //контрагенты (взаиморасчеты)
     $carr = unserialize(base64_decode($this->headerdata['c']));
     if (count($carr) > 0) {
         foreach ($carr as $c) {
             $val = $c->val;
             $acc = explode('_', $c->op);
             $sc = new SubConto($this, $acc[0], $acc[1] == 'd' ? $val : 0 - $val);
             $sc->setCustomer($c->customer_id);
             $sc->save();
         }
     }
     //денежные  счета
     $farr = unserialize(base64_decode($this->headerdata['f']));
     if (count($farr) > 0) {
         foreach ($farr as $f) {
             $val = $f->val;
             $acc = explode('_', $f->op);
             $sc = new SubConto($this, $acc[0], $acc[1] == 'd' ? $val : 0 - $val);
             $sc->setMoneyfund($f->id);
             $sc->save();
         }
     }
 }
示例#7
0
 public function Execute()
 {
     $diff = $this->headerdata['summa'] - $this->headerdata['actual'];
     Entry::AddEntry("282", "285", $diff, $this->document_id, $cash->id, $customer_id);
     $sc = new SubConto($this, 282, $diff);
     $sc->setStock($this->headerdata["stock_id"]);
     $sc->setQuantity($diff);
     $sc->save();
     $sc = new SubConto($this, 285, 0 - $diff);
     $sc->setExtCode($this->headerdata["store_id"]);
     $sc->save();
     return true;
 }
示例#8
0
 public function Execute()
 {
     $types = array();
     //аналитика
     foreach ($this->detaildata as $item) {
         $stock = \ZippyERP\ERP\Entity\Stock::getStock($this->headerdata['store'], $item['item_id'], $item['price'], true);
         $sc = new SubConto($this, $item['type'], $item['amount'] - $item['nds']);
         $sc->setStock($stock->stock_id);
         $sc->setQuantity($item['quantity']);
         $sc->save();
         //группируем по синтетическим счетам
         if ($types[$item['type']] > 0) {
             $types[$item['type']] = $types[$item['type']] + $item['amount'] - $item['nds'];
         } else {
             $types[$item['type']] = $item['amount'] - $item['nds'];
         }
     }
     foreach ($types as $acc => $value) {
         Entry::AddEntry($acc, "63", $value, $this->document_id, $this->document_date);
         $sc = new SubConto($this, 63, 0 - $value);
         $sc->setCustomer($this->headerdata["customer"]);
         $sc->save();
     }
     $total = $this->headerdata['total'];
     if ($this->headerdata['cash'] == true) {
         $cash = MoneyFund::getCash();
         Entry::AddEntry("63", "30", $total, $this->document_id, $this->document_date);
         $sc = new SubConto($this, 63, $total);
         $sc->setCustomer($this->headerdata["customer"]);
         $sc->save();
         $sc = new SubConto($this, 30, 0 - $total);
         $sc->setMoneyfund($cash->id);
         // $sc->save();
     }
     //налоговый кредит
     if ($this->headerdata['totalnds'] > 0) {
         Entry::AddEntry("644", "63", $this->headerdata['totalnds'], $this->document_id, $this->document_date);
         $sc = new SubConto($this, 63, 0 - $this->headerdata['totalnds']);
         $sc->setCustomer($this->headerdata["customer"]);
         $sc->save();
         $sc = new SubConto($this, 644, $this->headerdata['totalnds']);
         $sc->setExtCode(TAX_NDS);
         //$sc->save();
     }
     return true;
 }
示例#9
0
 public function Execute()
 {
     $diffall = 0;
     foreach ($this->detaildata as $value) {
         $diffall = $diffall + $value['quantity'] / 1000 * ($value['newprice'] - $value['price']);
         $stock = Stock::load($value["stock_id"]);
         $newstock = Stock::getStock($stock->store_id, $stock->item_id, $value['newprice'], true);
         $sc = new SubConto($this, 282, 0 - $value['quantity'] / 1000 * $stock->price);
         $sc->setStock($stock->stock_id);
         $sc->setQuantity(0 - $value['quantity']);
         $sc->save();
         $sc = new SubConto($this, 282, $value['quantity'] / 1000 * $newstock->price);
         $sc->setStock($newstock->stock_id);
         $sc->setQuantity($value['quantity']);
         $sc->save();
     }
     Entry::AddEntry("282", "285", $diffall, $this->document_id, $cash->id, $customer_id);
     $sc = new SubConto($this, 285, 0 - $diffall);
     $sc->setExtCode($this->headerdata["store"]);
     $sc->save();
     return true;
 }