示例#1
0
 private function saveLote($factura)
 {
     $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first();
     $branch = Branch::find(Session::get('branch_id'));
     // return $factura['nit'];
     $client = Client::where('account_id', '=', Auth::user()->account_id)->where('public_id', $factura['id'])->first();
     //if(!$client)
     //   return $factura['nit'];
     $invoice = Invoice::createNew();
     $invoice->setPublicNotes($factura['nota']);
     $invoice->setBranch(Session::get('branch_id'));
     $invoice->setInvoiceDate(date("Y-m-d"));
     $invoice->setClient($client->id);
     $invoice->setEconomicActivity($branch->economic_activity);
     $invoice->setDiscount(0);
     $invoice->setClientName($client->name);
     $invoice->setClientNit($client->nit);
     $invoice->setUser(Auth::user()->id);
     //$date=date("Y-m-d",strtotime(Input::get('invoice_date')));
     //$invoice->setInvoiceDate($date);
     $total_cost = 0;
     foreach ($factura['products'] as $producto) {
         //$pr = Product::where('account_id',Auth::user()->account_id)->where('product_key',$producto['product_key'])->first();
         //$total_cost+= $pr->cost*$producto['qty'];
         $total_cost += $producto['cost'];
     }
     $invoice->importe_neto = trim($total_cost);
     $invoice->importe_total = trim($total_cost);
     //$invoice->note = trim(Input::get('nota'));
     $invoice->setAccountName($account->name);
     $invoice->setAccountNit($account->nit);
     $invoice->setBranchName($branch->name);
     $invoice->setAddress1($branch->address1);
     $invoice->setAddress2($branch->address2);
     $invoice->setPhone($branch->work_phone);
     $invoice->setCity($branch->city);
     $invoice->setState($branch->state);
     $invoice->setNumberAutho($branch->number_autho);
     $invoice->setKeyDosage($branch->key_dosage);
     $invoice->setTypeThird($branch->type_third);
     $invoice->setDeadline($branch->deadline);
     $invoice->setLaw($branch->law);
     $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->first();
     $invoice->invoice_number = branch::getInvoiceNumber();
     $numAuth = $invoice->number_autho;
     $numfactura = $invoice->invoice_number;
     $nit = $invoice->client_nit;
     $fechaEmision = date("Ymd", strtotime($invoice->invoice_date));
     $total = $invoice->importe_neto;
     $llave = $branch->key_dosage;
     $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $total, $numAuth, $llave);
     $invoice->setControlCode($codigoControl);
     $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 1) {
             $id_documento = $actual_document->id;
         }
     }
     $invoice->setJavascript($id_documento);
     $invoice->logo = 1;
     $invoice->sfc = $branch->sfc;
     //$invoice->qr =$invoice->account_nit.'|'.$invoice->invoice_number.'|'.$invoice->number_autho.'|'.$invoice->invoice_date.'|'.$invoice->importe_neto.'|'.$invoice->importe_total.'|'.$invoice->client_nit.'|'.$invoice->importe_ice.'|0|0|'.$invoice->descuento_total;
     if ($account->is_uniper) {
         $invoice->account_uniper = $account->uniper;
     }
     //$invoice->logo = $type_document->logo;
     $invoice->save();
     foreach ($factura['products'] as $producto) {
         $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $producto['product_key'])->first();
         if ($product != null) {
             $invoiceItem = InvoiceItem::createNew();
             $invoiceItem->setInvoice($invoice->id);
             $invoiceItem->setProduct($product->id);
             $invoiceItem->setProductKey($product->product_key);
             $invoiceItem->setNotes($product->notes . " " . $producto['description']);
             $invoiceItem->setCost($producto['cost']);
             $invoiceItem->setQty(1);
             $invoiceItem->save();
         }
     }
 }
示例#2
0
 private function saveLote2($factura, $date)
 {
     //print_r($factura);
     //return;
     $account = DB::table('accounts')->where('id', '=', Auth::user()->account_id)->first();
     $branch = Branch::find(Session::get('branch_id'));
     $client = Client::where('account_id', '=', Auth::user()->account_id)->where('name', $factura['name'])->where('nit', $factura['nit'])->first();
     if (!$client) {
         ///echo "creo";
         $client = Client::createNew();
         $client->setNit(trim($factura['nit']));
         $client->setName(trim($factura['name']));
         $client->setBussinesName(trim($factura['razon']));
         $alt = $client->guardar();
         $client->save();
     }
     $invoice = Invoice::createNew();
     $invoice->setPublicNotes("");
     $invoice->setBranch(Session::get('branch_id'));
     $dateparser = explode("/", $date);
     $date = $dateparser[2] . '-' . $dateparser[1] . '-' . $dateparser[0];
     $invoice->setInvoiceDate($date);
     $invoice->setClient($client->id);
     $invoice->setEconomicActivity($branch->economic_activity);
     $invoice->setDiscount(0);
     $invoice->setClientName($client->business_name);
     $invoice->setClientNit($client->nit);
     $invoice->setUser(Auth::user()->id);
     $total_cost = 0;
     /*foreach ($factura['products'] as $producto)
       {
           $total_cost+= $producto['cost'];
       }*/
     $invoice->importe_neto = $factura['total'] * $factura['qty'];
     $invoice->importe_total = $factura['total'] * $factura['qty'];
     $invoice->debito_fiscal = $factura['total'] * $factura['qty'];
     //$invoice->note = trim(Input::get('nota'));
     $invoice->setAccountName($account->name);
     $invoice->setAccountNit($account->nit);
     $invoice->setBranchName($branch->name);
     $invoice->setAddress1($branch->address1);
     $invoice->setAddress2($branch->address2);
     $invoice->setPhone($branch->work_phone);
     $invoice->setCity($branch->city);
     $invoice->setState($branch->state);
     $invoice->setNumberAutho($branch->number_autho);
     $invoice->setKeyDosage($branch->key_dosage);
     $invoice->setTypeThird($branch->type_third);
     $invoice->setDeadline($branch->deadline);
     $invoice->setLaw($branch->law);
     $type_document = TypeDocument::where('account_id', Auth::user()->account_id)->firstOrFail();
     $invoice->invoice_number = branch::getInvoiceNumber();
     $numAuth = $invoice->number_autho;
     $numfactura = $invoice->invoice_number;
     $nit = $invoice->client_nit;
     $fechaEmision = date("Ymd", strtotime($invoice->invoice_date));
     $total = $invoice->importe_neto;
     $llave = $branch->key_dosage;
     $totalc = number_format((double) $total, 2, '.', '');
     if ($account->currency_id == 2) {
         $totalc = $total * $account->exchange;
         $totalc = number_format((double) $totalc, 2, '.', '');
     }
     $codigoControl = Utils::getControlCode($numfactura, $nit, $fechaEmision, $totalc, $numAuth, $llave);
     $invoice->setControlCode($codigoControl);
     $documents = TypeDocumentBranch::where('branch_id', $invoice->branch_id)->orderBy('id', 'ASC')->get();
     foreach ($documents as $document) {
         $actual_document = TypeDocument::where('id', $document->type_document_id)->first();
         if ($actual_document->master_id == 1) {
             $id_documento = $actual_document->id;
         }
     }
     $invoice->setJavascript($id_documento);
     $invoice->logo = 1;
     //$invoice->sfc = $branch->sfc;
     if ($account->currency_id == 1) {
         $invoice->sfc = 1;
     } else {
         $invoice->sfc = $account->exchange;
     }
     $invoice->qr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice->invoice_date . '|' . $invoice->importe_neto . '|' . $invoice->importe_total . '|' . $invoice->client_nit . '|' . $invoice->importe_ice . '|0|0|' . $invoice->descuento_total;
     if ($account->is_uniper) {
         $invoice->account_uniper = $account->uniper;
     }
     //$invoice->logo = $type_document->logo;
     $invoice->save();
     //foreach ($factura['products']  as $producto)
     //{
     $product = Product::where('account_id', Auth::user()->account_id)->where('product_key', $factura['code'])->first();
     if ($product != null) {
         $invoiceItem = InvoiceItem::createNew();
         $invoiceItem->setInvoice($invoice->id);
         $invoiceItem->setProduct($product->id);
         $invoiceItem->setProductKey($product->product_key);
         $invoiceItem->setNotes($product->notes);
         //$invoiceItem->setCost($factura['total']);
         $invoiceItem->setCost($factura['total']);
         $invoiceItem->setQty($factura['qty']);
         $invoiceItem->save();
     }
     // $this->sendInvoiceByMailLocal($client->name,$client->business_name,$invoice->id,$invoice->invoice_date,$client->nit);
     //}
 }