Ejemplo n.º 1
0
 public static function create($params, $currentUser, $con)
 {
     // check role's permission
     $permission = RolePermissionQuery::create()->select('create_sales')->findOneById($currentUser->role_id, $con);
     if (!$permission || $permission != 1) {
         throw new \Exception('Akses ditolak. Anda tidak mempunyai izin untuk melakukan operasi ini.');
     }
     // create new sales
     $sales = new Sales();
     $sales->setDate($params->date)->setSecondPartyId($params->second_party_id)->setBuyPrice($params->buy_price)->setTotalPrice($params->total_price)->setPaid($params->paid)->setCashierId($params->cashier_id)->setNote($params->note)->setStatus('Active')->save($con);
     // check wether this transaction is credit or not
     $balance = $params->paid - $params->total_price;
     if ($balance < 0) {
         $credit = new Credit();
         $credit->setSalesId($sales->getId())->setTotal(abs($balance))->setStatus('Active')->save($con);
     }
     $products = json_decode($params->products);
     foreach ($products as $product) {
         // create new record representing product stock which is being saled
         $salesDetail = new SalesDetail();
         $salesDetail->setSalesId($sales->getId())->setType($product->type)->setStockId($product->stock_id)->setAmount($product->amount)->setUnitPrice($product->unit_price)->setDiscount($product->discount)->setTotalPrice($product->total_price)->setBuy($product->buy)->setSellPublic($product->sell_public)->setSellDistributor($product->sell_distributor)->setSellMisc($product->sell_misc)->setStatus('Active')->save($con);
         // substract stock
         $stock = StockQuery::create()->findOneById($product->stock_id, $con);
         if ($stock->getUnlimited() == false) {
             $stock->setAmount($stock->getAmount() - $product->amount)->save($con);
         }
     }
     $logData['params'] = $params;
     // log history
     $salesHistory = new SalesHistory();
     $salesHistory->setUserId($currentUser->id)->setSalesId($sales->getId())->setTime(time())->setOperation('create')->setData(json_encode($logData))->save($con);
     $results['success'] = true;
     $results['id'] = $sales->getId();
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aSales) {
         $this->aSales->removeCredit($this);
     }
     $this->id = null;
     $this->sales_id = null;
     $this->total = null;
     $this->paid = null;
     $this->status = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Ejemplo n.º 3
0
 /**
  * Filter the query by a related \ORM\Sales object
  *
  * @param \ORM\Sales|ObjectCollection $sales  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildSecondPartyQuery The current query, for fluid interface
  */
 public function filterBySales($sales, $comparison = null)
 {
     if ($sales instanceof \ORM\Sales) {
         return $this->addUsingAlias(SecondPartyTableMap::COL_ID, $sales->getSecondPartyId(), $comparison);
     } elseif ($sales instanceof ObjectCollection) {
         return $this->useSalesQuery()->filterByPrimaryKeys($sales->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterBySales() only accepts arguments of type \\ORM\\Sales or Collection');
     }
 }
Ejemplo n.º 4
0
 /**
  * Filter the query by a related \ORM\Sales object
  *
  * @param \ORM\Sales|ObjectCollection $sales The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCreditQuery The current query, for fluid interface
  */
 public function filterBySales($sales, $comparison = null)
 {
     if ($sales instanceof \ORM\Sales) {
         return $this->addUsingAlias(CreditTableMap::COL_SALES_ID, $sales->getId(), $comparison);
     } elseif ($sales instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CreditTableMap::COL_SALES_ID, $sales->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterBySales() only accepts arguments of type \\ORM\\Sales or Collection');
     }
 }
Ejemplo n.º 5
0
 /**
  * @param ChildSales $sales The ChildSales object to add.
  */
 protected function doAddSales(ChildSales $sales)
 {
     $this->collSaless[] = $sales;
     $sales->setCashier($this);
 }
Ejemplo n.º 6
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aSales) {
         $this->aSales->removeDetail($this);
     }
     if (null !== $this->aStock) {
         $this->aStock->removeSales($this);
     }
     $this->id = null;
     $this->sales_id = null;
     $this->type = null;
     $this->stock_id = null;
     $this->amount = null;
     $this->unit_price = null;
     $this->discount = null;
     $this->total_price = null;
     $this->buy = null;
     $this->sell_public = null;
     $this->sell_distributor = null;
     $this->sell_misc = null;
     $this->status = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }
Ejemplo n.º 7
0
 /**
  * Exclude object from result
  *
  * @param   ChildSales $sales Object to remove from the list of results
  *
  * @return $this|ChildSalesQuery The current query, for fluid interface
  */
 public function prune($sales = null)
 {
     if ($sales) {
         $this->addUsingAlias(SalesTableMap::COL_ID, $sales->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Clears the current object, sets all attributes to their default values and removes
  * outgoing references as well as back-references (from other objects to this one. Results probably in a database
  * change of those foreign objects when you call `save` there).
  */
 public function clear()
 {
     if (null !== $this->aUserDetail) {
         $this->aUserDetail->removeSalesHistory($this);
     }
     if (null !== $this->aSales) {
         $this->aSales->removeHistory($this);
     }
     $this->id = null;
     $this->user_id = null;
     $this->sales_id = null;
     $this->time = null;
     $this->operation = null;
     $this->data = null;
     $this->alreadyInSave = false;
     $this->clearAllReferences();
     $this->resetModified();
     $this->setNew(true);
     $this->setDeleted(false);
 }