Beispiel #1
0
 public static function Create($orderId, $itemId, $itemName, $quantity, $vatrate, $unitPrice, $unitCost, $discount)
 {
     //check whether available and make necessary inventory deductions, then
     $vat = intval($vatrate) / (intval($vatrate) + 100) * (intval($quantity) * floatval($unitPrice));
     $discount = floatval($discount);
     $lineItem = new OrderLine($orderId, $itemId, $itemName, $quantity, $vat, $unitPrice, $unitCost, $discount);
     try {
         $sql = 'SELECT * FROM stock_accounts WHERE resource_id = ' . $itemId;
         $res = DatabaseHandler::GetRow($sql);
         if ($res['stock_bal'] >= intval($quantity)) {
             $lineItem->setAvailabile();
             $sql = 'UPDATE stock_accounts SET stock_bal = ' . (intval($res['stock_bal']) - intval($quantity)) . ' WHERE resource_id = ' . $itemId;
             DatabaseHandler::Execute($sql);
         } else {
         }
         $lineItem->save();
         return $lineItem;
     } catch (Exception $e) {
     }
 }