function createSale($sellerID, $itemType, $itemID, $price) { $NewSale = new Sale(); $NewSale->SellerID = $sellerID; $NewSale->ItemType = $itemType; $NewSale->ItemID = $itemID; $NewSale->Price = $price; $NewSale->Created = new DateTime('now'); $NewSale->save(); return $NewSale; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Sale(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Sale'])) { $model->attributes = $_POST['Sale']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function saveInSaleTable() { try { $input = Input::all(); $saleTable = new Sale(); $saleTable->user_id = Auth::user()->id; $saleTable->branch_id = $input['branch_id']; $saleTable->comments = $input['fechareal'] . ' ' . $input['documento'] . ' ' . $input['nombre'] . ' ' . $input['nit'] . ' ' . $input['direccion']; $saleTable->status = 'pendiente'; $saleTable->save(); return $saleTable; } catch (Exception $e) { die('No se pudo guardar el registro en ventas.'); } }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param ConnectionInterface $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(ConnectionInterface $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their corresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aSale !== null) { if ($this->aSale->isModified() || $this->aSale->isNew()) { $affectedRows += $this->aSale->save($con); } $this->setSale($this->aSale); } if ($this->aProduct !== null) { if ($this->aProduct->isModified() || $this->aProduct->isNew()) { $affectedRows += $this->aProduct->save($con); } $this->setProduct($this->aProduct); } if ($this->aAttributeAv !== null) { if ($this->aAttributeAv->isModified() || $this->aAttributeAv->isNew()) { $affectedRows += $this->aAttributeAv->save($con); } $this->setAttributeAv($this->aAttributeAv); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aProduct !== null) { if ($this->aProduct->isModified() || $this->aProduct->isNew()) { $affectedRows += $this->aProduct->save($con); } $this->setProduct($this->aProduct); } if ($this->aSale !== null) { if ($this->aSale->isModified() || $this->aSale->isNew()) { $affectedRows += $this->aSale->save($con); } $this->setSale($this->aSale); } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = ProductHasSalePeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setNew(false); } else { $affectedRows += ProductHasSalePeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
private function saveSale($venta) { $input = $venta; $numero = (int) $input->invoice_number; $client_id = $this->clientId($input->client_id); $user_id = $input->user_id; $items = $input->invoice_items; $amount = 0; $subtotal = 0; $fiscal = 0; $icetotal = 0; $bonidesc = 0; foreach ($items as $item) { $product_id = $item->id; $qty = (int) $item->qty; $cost = $item->cost / $item->units; $st = $cost * $qty; $subtotal = $subtotal + $st; $bd = $item->boni * $cost + $item->desc; $bonidesc = $bonidesc + $bd; $amount = $amount + $st - $bd; if ($item->ice == 1) { //caluclo ice bruto $iceBruto = $qty * ($item->cc / 1000) * $input->ice; $iceNeto = (int) $item->boni * ($item->cc / 1000) * $input->ice; $icetotal = $icetotal + ($iceBruto - $iceNeto); } } $fiscal = $amount - $bonidesc - $icetotal; $balance = $amount; $invoice_dateCC = date("Ymd"); $invoice_date = date("Y-m-d"); $invoice_date_limitCC = date("Y-m-d", strtotime($input->deadline)); $cod_control = $input->cod_control; // creando invoice $sale = new Sale(); $sale->invoice_number = $input->invoice_number; $sale->client_id = $client_id; $sale->user_id = $user_id; $sale->account_id = $input->account_id; $sale->branch_id = $input->branch_id; $sale->amount = number_format((double) $amount, 2, '.', ''); $sale->subtotal = $subtotal; $sale->fiscal = $fiscal; $sale->law = $input->law; $sale->balance = $balance; $sale->control_code = $cod_control; $sale->start_date = $invoice_date; $sale->invoice_date = $invoice_date; ///datos de branch $sale->activity_pri = $input->activity_pri; $sale->activity_sec1 = $input->activity_sec1; $sale->end_date = $invoice_date_limitCC; $sale->address1 = $input->address1; $sale->address2 = $input->address2; $sale->number_autho = $input->number_autho; $sale->work_phone = $input->postal_code; $sale->city = $input->city; $sale->state = $input->state; $sale->country_id = $input->country_id; $sale->key_dosage = $input->key_dosage; $sale->deadline = $input->deadline; $sale->custom_value1 = $icetotal; $sale->ice = $input->ice; //cliente $sale->nit = $input->nit; $sale->name = $input->name; $sale->save(); //$account = Auth::user()->account; $ice = $sale->amount - $sale->fiscal; $desc = $sale->subtotal - $sale->amount; $amount = number_format($sale->amount, 2, '.', ''); $fiscal = number_format($sale->fiscal, 2, '.', ''); $icef = number_format($ice, 2, '.', ''); $descf = number_format($desc, 2, '.', ''); if ($icef == "0.00") { $icef = 0; } if ($descf == "0.00") { $descf = 0; } $sale->qr = ""; //=HTML::image_data('qr/' . $account->account_key .'_'. $input->invoice_number . '.jpg'); $sale->save(); $fecha = $input->fecha; $f = date("Y-m-d", strtotime($fecha)); DB::table('sales')->where('id', $sale->id)->update(array('branch' => $input->branch, 'invoice_date' => $f)); foreach ($items as $item) { $product_id = $item->id; $cost = $item->cost / $item->units; $line_total = (int) $item->qty * $cost; $product = new Product(); $product->sale_id = $sale->id; $product->product_id = $product_id; $product->product_key = $item->product_key; $product->notes = $item->notes; $product->cost = $cost; $product->boni = (int) $item->boni; $product->desc = $item->desc; $product->qty = (int) $item->qty; $product->line_total = $line_total; $product->tax_rate = 0; $product->save(); } }