public static function fromArray($data) { $item = new InvoiceItem(); if (isset($data['quantity'])) { $item->setQuantity($data['quantity']); } if (isset($data['vat'])) { $item->setVat($data['vat']); } if (isset($data['price_item'])) { $item->setPriceItem($data['price_item']); } if (isset($data['price'])) { $item->setPrice($data['price']); } if (isset($data['price_total'])) { $item->setPriceTotal($data['price_total']); } if (isset($data['description'])) { $item->setPriceTotal($data['description']); } if (isset($data['discount']) && is_array($data['discount'])) { $item->setDiscount(Discount::fromArray($data['discount'])); } return $item; }
/** * Delete item to invoice */ public function delete($invoice, $id) { if (InvoiceItem::destroy($id)) { return Redirect::route('invoice_modify', $invoice)->with('mSucces', 'La ligne a bien été supprimée'); } else { return Redirect::route('invoice_modify', $invoice)->with('mError', 'Impossible de supprimer cette ligne'); } }
public function invoiceItems($params = null) { if (!$params) { $params = array(); } $params['customer'] = $this->id; $iis = InvoiceItem::all($params, $this->_apiKey); return $iis; }
public function fire() { $this->info(date('Y-m-d') . ' Running SendRecurringInvoices...'); $today = new DateTime(); $invoices = Invoice::with('account.timezone', 'invoice_items', 'client')->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', array($today, $today))->get(); $this->info(count($invoices) . ' recurring invoice(s) found'); foreach ($invoices as $recurInvoice) { if ($recurInvoice->client->deleted_at) { continue; } date_default_timezone_set($recurInvoice->account->getTimezone()); $this->info('Processing Invoice ' . $recurInvoice->id . ' - Should send ' . ($recurInvoice->shouldSendToday() ? 'YES' : 'NO')); if (!$recurInvoice->shouldSendToday()) { continue; } $invoice = Invoice::createNew($recurInvoice); $invoice->client_id = $recurInvoice->client_id; $invoice->recurring_invoice_id = $recurInvoice->id; $invoice->invoice_number = 'R' . $recurInvoice->account->getNextInvoiceNumber(); $invoice->amount = $recurInvoice->amount; $invoice->balance = $recurInvoice->amount; $invoice->invoice_date = date_create()->format('Y-m-d'); $invoice->discount = $recurInvoice->discount; $invoice->po_number = $recurInvoice->po_number; $invoice->public_notes = $recurInvoice->public_notes; $invoice->terms = $recurInvoice->terms; $invoice->tax_name = $recurInvoice->tax_name; $invoice->tax_rate = $recurInvoice->tax_rate; $invoice->invoice_design_id = $recurInvoice->invoice_design_id; if ($invoice->client->payment_terms) { $invoice->due_date = date_create()->modify($invoice->client->payment_terms . ' day')->format('Y-m-d'); } $invoice->save(); foreach ($recurInvoice->invoice_items as $recurItem) { $item = InvoiceItem::createNew($recurItem); $item->product_id = $recurItem->product_id; $item->qty = $recurItem->qty; $item->cost = $recurItem->cost; $item->notes = Utils::processVariables($recurItem->notes); $item->product_key = Utils::processVariables($recurItem->product_key); $item->tax_name = $recurItem->tax_name; $item->tax_rate = $recurItem->tax_rate; $invoice->invoice_items()->save($item); } foreach ($recurInvoice->invitations as $recurInvitation) { $invitation = Invitation::createNew($recurInvitation); $invitation->contact_id = $recurInvitation->contact_id; $invitation->invitation_key = str_random(RANDOM_KEY_LENGTH); $invoice->invitations()->save($invitation); } $this->mailer->sendInvoice($invoice); $recurInvoice->last_sent_date = Carbon::now()->toDateTimeString(); $recurInvoice->save(); } $this->info('Done'); }
public function testItemsAccessWithParameter() { self::authorizeFromEnv(); $customer = self::createTestCustomer(); InvoiceItem::create(array('customer' => $customer->id, 'amount' => 100, 'currency' => 'usd')); $invoice = Invoice::upcoming(array('customer' => $customer->id)); $lines = $invoice->lines->all(array('limit' => 10)); $this->assertSame(count($lines->data), 1); $this->assertSame($lines->data[0]->amount, 100); }
public function run() { Eloquent::unguard(); DB::table('invoices')->truncate(); DB::table('invoice_items')->truncate(); $faker = Faker\Factory::create(); for ($i = 0; $i < 30; $i++) { $invoice = Invoice::create(array('user_id' => $faker->randomNumber(1, 20), 'due_date' => $faker->dateTimeThisYear, 'status' => $faker->randomElement(array('Draft', 'Unpaid', 'Paid')))); InvoiceItem::create(array('invoice_id' => $invoice->id, 'description' => $faker->sentence, 'unit_price' => $faker->randomNumber(1, 200), 'quantity' => $faker->randomNumber(1, 2))); } }
public static function getActiveSubscriptionInfos() { $params = array(); $active_subscription = InvoiceItem::where('ressource_id', Ressource::TYPE_COWORKING)->where('invoices.user_id', Auth::user()->id)->where('subscription_from', '<', date('Y-m-d'))->where('subscription_to', '>', date('Y-m-d'))->join('invoices', function ($j) { $j->on('invoice_id', '=', 'invoices.id')->where('type', '=', 'F'); })->first(); $params['active_subscription'] = $active_subscription; if ($active_subscription) { $params['subscription_used'] = PastTime::recap(Auth::user()->id, $active_subscription->subscription_from, $active_subscription->subscription_to, Ressource::TYPE_COWORKING, false)->first(); } else { $params['subscription_used'] = array('hours' => 0, 'minutes' => 0); } if ($active_subscription && $params['subscription_used']) { $params['subscription_ratio'] = round(100 * ($params['subscription_used']->hours + $params['subscription_used']->minutes / 60) / $active_subscription->subscription_hours_quota); } else { $params['subscription_ratio'] = 0; } return $params; }
public function sales_per_category() { $colors = array(); $colors[] = '#a3e1d4'; $colors[] = '#dedede'; $colors[] = '#b5b8cf'; $data = array(); foreach (InvoiceItem::total()->byKind()->get() as $item) { $data[$item->kind ? $item->kind : self::LABEL_OTHERS] = array('amount' => $item->total, 'color' => array_shift($colors)); } $total = 0; foreach ($data as $k => $v) { $total += $data[$k]['amount']; } foreach ($data as $k => $v) { $data[$k]['ratio'] = $total ? sprintf('%0.2f', 100 * $data[$k]['amount'] / $total) : 0; } return View::make('stats.pie', array('data' => $data, 'total' => $total)); }
public function vat() { $paid = array(); $paid_rates = array(); $sum = array(); foreach (ChargeItem::TotalTVA() as $item) { $paid[$item->days][$item->value] = $item->total; $paid_rates[$item->value] = true; if (empty($sum[$item->days])) { $sum[$item->days] = 0; } $sum[$item->days] += $item->total; } $received = array(); $received_rates = array(); foreach (InvoiceItem::TotalTVA()->get() as $item) { $received[$item->days][$item->value] = $item->total; $received_rates[$item->value] = true; if (empty($sum[$item->days])) { $sum[$item->days] = 0; } $sum[$item->days] -= $item->total; } krsort($sum); ksort($paid_rates); ksort($received_rates); $month2quarter = array('01' => 1, '02' => 1, '03' => 1, '04' => 2, '05' => 2, '06' => 2, '07' => 3, '08' => 3, '09' => 3, '10' => 4, '11' => 4, '12' => 4); $overview = array(); foreach ($sum as $period => $value) { if (preg_match('/(.+)-(.+)/', $period, $matchs)) { $quarter = sprintf('%s-Q%s', $matchs[1], $month2quarter[$matchs[2]]); if (!isset($overview[$quarter])) { $overview[$quarter] = 0; } $overview[$quarter] += $value; } } krsort($overview); return View::make('cashflow.vat', array('paid' => $paid, 'received' => $received, 'sum' => $sum, 'overview' => $overview, 'paid_rates' => array_keys($paid_rates), 'received_rates' => array_keys($received_rates))); }
public function renew($id) { $subscription = $this->dataExist($id); $invoice = new Invoice(); $invoice->type = 'F'; $invoice->user_id = $subscription->user_id; $invoice->organisation_id = $subscription->organisation_id; $invoice->days = date('Ym'); $invoice->date_invoice = date('Y-m-d'); $invoice->number = Invoice::next_invoice_number($invoice->type, $invoice->days); $invoice->address = $subscription->organisation->fulladdress; $date = new DateTime($invoice->date_invoice); $date->modify('+1 month'); $invoice->deadline = $date->format('Y-m-d'); $invoice->save(); $invoice_line = new InvoiceItem(); $invoice_line->invoice_id = $invoice->id; $invoice_line->ressource_id = Ressource::TYPE_COWORKING; $invoice_line->amount = $subscription->kind->price; $date = new \DateTime($subscription->renew_at); $date2 = new \DateTime($subscription->renew_at); $invoice_line->subscription_from = $date->format('Y-m-d'); $date2->modify('next month'); $invoice_line->subscription_to = $date2->format('Y-m-d'); $invoice_line->subscription_hours_quota = $subscription->kind->hours_quota; // update invoices_items set subscription_to = date_add(subscription_from, interval 1 MONTH) where subscription_from <> '0000-00-00 00:00:00' $date2->modify('-1 day'); $invoice_line->text = sprintf("%s - %s\nDu %s au %s", $subscription->kind->name, $subscription->user->fullname, $date->format('d/m/Y'), $date2->format('d/m/Y')); $invoice_line->vat_types_id = VatType::whereValue(20)->first()->id; $invoice_line->ressource_id = Ressource::TYPE_COWORKING; $invoice_line->save(); $invoice_line->order_index = 1; $date = new DateTime($subscription->renew_at); $date->modify('+1 month'); $subscription->renew_at = $date->format('Y-m-d'); $subscription->save(); return Redirect::route('invoice_modify', $invoice->id)->with('mSuccess', 'La facture a été créée'); }
public function calculate(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentAmount = 0.0, $paymentDate = 'now', &$matchedRules = array()) { // take aff.commission_days in account for 1-tier only if ($tier == 0 && ($commissionDays = $this->getDi()->config->get('aff.commission_days'))) { $signupDays = $this->getDi()->time - strtotime($invoice->getUser()->aff_added ? $invoice->getUser()->aff_added : $invoice->getUser()->added); $signupDays = intval($signupDays / (3600 * 24)); // to days if ($commissionDays < $signupDays) { return; } // no commission for this case, affiliate<->user relation is expired } $multi = 1.0; $isFirst = $paymentNumber <= 1; $prefix = $isFirst && (double) $item->first_total ? 'first' : 'second'; if ($tier == 0) { if ($invoice->get("{$prefix}_total") == 0) { $paidForItem = 0; } else { $paidForItem = $paymentAmount * $item->get("{$prefix}_total") / $invoice->get("{$prefix}_total"); } } else { // for higher tier just take amount paid to previous tier $paidForItem = $paymentAmount; } $paidForItem = $tier ? $paidForItem : $paidForItem / $invoice->base_currency_multi; foreach ($this->findRules($invoice, $item, $aff, $paymentNumber, $tier, $paymentDate) as $rule) { array_push($matchedRules, $rule); // Second tier commission have to be calculated as percent from First tier commission. if ($tier > 0) { return moneyRound($rule->first_payment_c * $paidForItem / 100); } if ($rule->type == AffCommissionRule::TYPE_MULTI) { $multi *= $rule->multi; } else { if ($paidForItem == 0) { // free signup? if ($paymentNumber == 0 && $rule->free_signup_c) { return moneyRound($multi * $rule->free_signup_c); } } elseif ($isFirst) { // first payment if ($rule->first_payment_t == '%') { return moneyRound($multi * $rule->first_payment_c * $paidForItem / 100); } else { return moneyRound($multi * $rule->first_payment_c); } } else { // recurring payment if ($rule->recurring_t == '%') { return moneyRound($multi * $rule->recurring_c * $paidForItem / 100); } else { return moneyRound($multi * $rule->recurring_c); } } } } }
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(); } } }
} } // GENERATE RECEIPT FOR CHARGE NOT CHARGED YET $table_charge = new Table("cc_charge", "*"); $result = $table_charge->Get_list($DBHandle, $clause_charge . " AND charged_status = 0 AND invoiced_status = 0"); if (is_array($result) && sizeof($result) > 0) { foreach ($result as $charge) { $item = new InvoiceItem(null, gettext("CHARGE :") . $charge['description'], $charge['creationdate'], $charge['amount'], $vat, 'CHARGE'); $invoice_items[] = $item; } } // behaviour postpaid if ($typepaid == 1 && $credit < 0) { //GENERATE AN INVOICE TO COMPLETE THE BALANCE $amount = abs($credit); $item = new InvoiceItem(null, $desc_billing_postpaid, gmdate("Y/m/d H:i:s"), $amount, $vat, 'POSTPAID'); $invoice_items[] = $item; } $smarty->display('main.tpl'); $curr = $_SESSION['currency']; $currencies_list = get_currencies(); if (!isset($currencies_list[strtoupper($curr)][2]) || !is_numeric($currencies_list[strtoupper($curr)][2])) { $mycur = 1; $display_curr = strtoupper(BASE_CURRENCY); } else { $mycur = $currencies_list[strtoupper($curr)][2]; $display_curr = strtoupper($curr); } function amount_convert($amount) { global $mycur;
public function guardarFactura() { /* David Guardando factura con el siguiente formato: {"invoice_items":[{"qty":"2","id":"2"}],"client_id":"1"} //nuevo formato para la cascada XD {"invoice_items":[{"qty":"2","id":"2","boni":"1","desc":"3"}],"client_id":"1"} //para version generica {"invoice_items":[{"qty":"6","id":"11"}],"name":"Sin Nombre","nit":"0","client_id":"19"} */ $input = Input::all(); // $invoice_number = Auth::user()->account->getNextInvoiceNumber(); $invoice_number = Auth::user()->branch->getNextInvoiceNumber(); $client_id = $input['client_id']; $clientF = Client::scope($client_id)->firstOrFail(); $client = (object) array(); $client->id = $clientF->id; $client->name = $clientF->name; $client->nit = $clientF->nit; $client->public_id = $clientF->public_id; DB::table('clients')->where('id', $client->id)->update(array('nit' => $input['nit'], 'name' => $input['name'])); // $user_id = Auth::user()->getAuthIdentifier(); $user = DB::table('users')->select('account_id', 'branch_id', 'public_id')->where('id', $user_id)->first(); $account = DB::table('accounts')->where('id', $user->account_id)->first(); // //$account_id = $user->account_id; // // $account = DB::table('accounts')->select('num_auto','llave_dosi','fecha_limite')->where('id',$user->account_id)->first(); // //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id',$user['branch_id'])->first(); // //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id','=',$user->branch_id)->first(); // // $branch = DB::table('branches')->select('number_autho','key_dosage','deadline','address1','address2','country_id','industry_id','law','activity_pri','activity_sec1','name')->where('id','=',$user->branch_id)->first(); $branch = DB::table('branches')->where('id', '=', $user->branch_id)->first(); $invoice_design = DB::table('invoice_designs')->select('id')->where('account_id', '=', $user->account_id)->first(); // return Response::json($invoice_design); $items = $input['invoice_items']; // $linea =""; $amount = 0; $subtotal = 0; $fiscal = 0; $icetotal = 0; $bonidesc = 0; $productos = array(); foreach ($items as $item) { # code... $product_id = $item['id']; $pr = DB::table('products')->where('products.id', "=", $product_id)->first(); // $pr->xd ='hola'; //me quede aqui me llego sueñito XD $amount = $amount + $pr->cost * $item['qty']; // $pr->qty = 1; $productos = $pr; // $pr = DB::table('products')->select('cost')->where('id',$product_id)->first(); // $qty = (int) $item['qty']; // $cost = $pr->cost/$pr->units; // $st = ($cost * $qty); // $subtotal = $subtotal + $st; // $bd= ($item['boni']*$cost) + $item['desc']; // $bonidesc= $bonidesc +$bd; // $amount = $amount +$st-$bd; // // $fiscal = $fiscal +$amount; } // $fiscal = $amount -$bonidesc-$icetotal; $balance = $amount; $subtotal = $amount; // /////////////////////////hasta qui esta bien al parecer hacer prueba de que fuciona el join de los productos XD $invoice_dateCC = date("Ymd"); $invoice_date = date("Y-m-d"); $invoice_date_limitCC = date("Y-m-d", strtotime($branch->deadline)); require_once app_path() . '/includes/control_code.php'; $cod_control = codigoControl($invoice_number, $client->nit, $invoice_dateCC, $amount, $branch->number_autho, $branch->key_dosage); // $ice = DB::table('tax_rates')->select('rate')->where('name','=','ice')->first(); // // // // creando invoice $invoice = Invoice::createNew(); $invoice->invoice_number = $invoice_number; $invoice->client_id = $client->id; $invoice->user_id = $user_id; $invoice->account_id = $user->account_id; $invoice->branch_id = $user->branch_id; $invoice->amount = number_format((double) $amount, 2, '.', ''); $invoice->invoice_design_id = $invoice_design->id; //------------- hasta aqui funciona despues sale error $invoice->law = $branch->law; $invoice->balance = $balance; $invoice->subtotal = $subtotal; $invoice->control_code = $cod_control; $invoice->start_date = $invoice_date; $invoice->invoice_date = $invoice_date; $invoice->activity_pri = $branch->activity_pri; $invoice->activity_sec1 = $branch->activity_sec1; // // $invoice->invoice $invoice->end_date = $invoice_date_limitCC; // //datos de la empresa atra vez de una consulta XD // /*****************error generado al intentar guardar **/ // // $invoice->branch = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->number_autho = $branch->number_autho; // $invoice->work_phone=$branch->postal_code; $invoice->city = $branch->city; $invoice->state = $branch->state; // // $invoice->industry_id=$branch->industry_id; // $invoice->country_id= $branch->country_id; $invoice->key_dosage = $branch->key_dosage; $invoice->deadline = $branch->deadline; // $invoice->custom_value1 =$icetotal; // $invoice->ice = $ice->rate; // //cliente // $invoice->nit=$client->nit; // $invoice->name =$client->name; //adicionales de la nueva plataforma $invoice->account_name = $account->name; $invoice->account_nit = $account->nit; $invoice->client_name = $input['name']; $invoice->client_nit = $input['nit']; $invoice->phone = $branch->postal_code; $invoice->save(); // $account = Auth::user()->account; // $ice = $invoice->amount-$invoice->fiscal; // $desc = $invoice->subtotal-$invoice->amount; // $amount = number_format($invoice->amount, 2, '.', ''); // $fiscal = number_format($invoice->fiscal, 2, '.', ''); // $icef = number_format($ice, 2, '.', ''); // $descf = number_format($desc, 2, '.', ''); // if($icef=="0.00"){ // $icef = 0; // } // if($descf=="0.00"){ // $descf = 0; // } require_once app_path() . '/includes/BarcodeQR.php'; $icef = 0; $descf = 0; $qr = new BarcodeQR(); $datosqr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $invoice->amount . '|' . $invoice->amount . '|' . $invoice->nit . '|' . $icef . '|0|0|' . $descf; $qr->text($datosqr); $qr->draw(150, 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'); $input_file = 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'; $output_file = 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.jpg'; $inputqr = imagecreatefrompng($input_file); list($width, $height) = getimagesize($input_file); $output = imagecreatetruecolor($width, $height); $white = imagecolorallocate($output, 255, 255, 255); imagefilledrectangle($output, 0, 0, $width, $height, $white); imagecopy($output, $inputqr, 0, 0, 0, 0, $width, $height); imagejpeg($output, $output_file); $invoice->qr = HTML::image_data('qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.jpg'); $invoice->save(); DB::table('invoices')->where('id', $invoice->id)->update(array('branch_name' => $branch->name)); //error verificar // $invoice = DB::table('invoices')->select('id')->where('invoice_number',$invoice_number)->first(); //guardadndo los invoice items foreach ($items as $item) { // $product = DB::table('products')->select('notes')->where('id',$product_id)->first(); $product_id = $item['id']; $product = DB::table('products')->where('products.id', "=", $product_id)->first(); // $pr = DB::table('products')->select('cost')->where('id',$product_id)->first(); // $cost = $product->cost/$product->units; // $line_total= ((int)$item['qty'])*$cost; $invoiceItem = InvoiceItem::createNew(); $invoiceItem->invoice_id = $invoice->id; $invoiceItem->product_id = $product_id; $invoiceItem->product_key = $product->product_key; $invoiceItem->notes = $product->notes; $invoiceItem->cost = $product->cost; $invoiceItem->qty = $item['qty']; // $invoiceItem->line_total=$line_total; $invoiceItem->tax_rate = 0; $invoiceItem->save(); } $invoiceItems = DB::table('invoice_items')->select('notes', 'cost', 'qty')->where('invoice_id', '=', $invoice->id)->get(array('notes', 'cost', 'qty')); $date = new DateTime($invoice->deadline); $dateEmision = new DateTime($invoice->invoice_date); $cuenta = array('name' => $account->name, 'nit' => $account->nit); // $ice = $invoice->amount-$invoice->fiscal; // $factura = array('invoice_number' => $invoice->invoice_number, // 'control_code'=>$invoice->control_code, // 'invoice_date'=>$dateEmision->format('d-m-Y'), // 'amount'=>number_format((float)$invoice->amount, 2, '.', ''), // 'subtotal'=>number_format((float)$invoice->subtotal, 2, '.', ''), // 'fiscal'=>number_format((float)$invoice->fiscal, 2, '.', ''), // 'client'=>$client, // // 'id'=>$invoice->id, // 'account'=>$account, // 'law' => $invoice->law, // 'invoice_items'=>$invoiceItems, // 'address1'=>str_replace('+', '°', $invoice->address1), // // 'address2'=>str_replace('+', '°', $invoice->address2), // 'address2'=>$invoice->address2, // 'num_auto'=>$invoice->number_autho, // 'fecha_limite'=>$date->format('d-m-Y'), // // 'fecha_emsion'=>, // 'ice'=>number_format((float)$ice, 2, '.', '') // ); $client->name = $input['name']; $client->nit = $input['nit']; $factura = array('invoice_number' => $invoice->invoice_number, 'control_code' => $invoice->control_code, 'invoice_date' => $dateEmision->format('d-m-Y'), 'activity_pri' => $branch->activity_pri, 'amount' => number_format((double) $invoice->amount, 2, '.', ''), 'subtotal' => number_format((double) $invoice->balance, 2, '.', ''), 'fiscal' => number_format((double) $invoice->fiscal, 2, '.', ''), 'client' => $client, 'account' => $account, 'law' => $invoice->law, 'invoice_items' => $invoiceItems, 'address1' => str_replace('+', '°', $invoice->address1), 'address2' => $invoice->address2, 'num_auto' => $invoice->number_autho, 'fecha_limite' => $date->format('d-m-Y')); // $invoic = Invoice::scope($invoice_number)->withTrashed()->with('client.contacts', 'client.country', 'invoice_items')->firstOrFail(); // $d = Input::all(); //en caso de problemas irracionales me refiero a que se jodio // $input = Input::all(); // $client_id = $input['client_id']; // $client = DB::table('clients')->select('id','nit','name')->where('id',$input['client_id'])->first(); return Response::json($factura); }
private function export() { $output = fopen('php://output', 'w') or Utils::fatalError(); header('Content-Type:application/csv'); header('Content-Disposition:attachment;filename=export.csv'); $clients = Client::scope()->get(); AccountController::exportData($output, $clients->toArray()); $contacts = Contact::scope()->get(); AccountController::exportData($output, $contacts->toArray()); $invoices = Invoice::scope()->get(); AccountController::exportData($output, $invoices->toArray()); $invoiceItems = InvoiceItem::scope()->get(); AccountController::exportData($output, $invoiceItems->toArray()); $payments = Payment::scope()->get(); AccountController::exportData($output, $payments->toArray()); $credits = Credit::scope()->get(); AccountController::exportData($output, $credits->toArray()); fclose($output); exit; }
public function guardarFacturaOffline() { /* David Guardando factura con el siguiente formato: //Formato Offline //nuevo formato para la cascada XD {"invoice_items":[{"qty":"2","id":"2","boni":"1","desc":"3"}],"client_id":"1","nit":"6047054","name":"torrez","public_id":"1","invoice_date":"14-10-2014","invoice_number":"0001","cod_control"} */ $input = Input::all(); // $invoice_number = Auth::user()->account->getNextInvoiceNumber(); $invoice_number = (int) Auth::user()->branch->getNextInvoiceNumber(); $numero = (int) $input['invoice_number']; // $numero =(int) $input['invoice_number']; if ($invoice_number != $numero) { return Response::json(array('resultado' => '1', 'invoice_number' => $invoice_number)); } $client_id = $input['client_id']; // $client = DB::table('clients')->select('id','nit','name','public_id')->where('id',$input['client_id'])->first(); $user_id = Auth::user()->getAuthIdentifier(); $user = DB::table('users')->select('account_id', 'branch_id', 'price_type_id')->where('id', $user_id)->first(); //$account_id = $user->account_id; // $account = DB::table('accounts')->select('num_auto','llave_dosi','fecha_limite')->where('id',$user->account_id)->first(); //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id',$user['branch_id'])->first(); //$branch = DB::table('branches')->select('num_auto','llave_dosi','fecha_limite','address1','address2','country_id','industry_id')->where('id','=',$user->branch_id)->first(); // $branch = DB::table('branches')->select('number_autho','key_dosage','deadline','address1','address2','country_id','industry_id','law','activity_pri','activity_sec1','name')->where('id','=',$user->branch_id)->first(); $branch = DB::table('branches')->where('id', '=', $user->branch_id)->first(); $items = $input['invoice_items']; // $linea =""; $amount = 0; $subtotal = 0; $fiscal = 0; $icetotal = 0; $bonidesc = 0; foreach ($items as $item) { # code... $product_id = $item['id']; $pr = DB::table('products')->join('prices', "product_id", "=", 'products.id')->select('products.id', 'products.notes', 'prices.cost', 'products.ice', 'products.units', 'products.cc')->where('prices.price_type_id', '=', $user->price_type_id)->where('products.account_id', '=', $user->account_id)->where('products.id', "=", $product_id)->first(); // $pr = DB::table('products')->select('cost')->where('id',$product_id)->first(); $qty = (int) $item['qty']; $cost = $pr->cost / $pr->units; $st = $cost * $qty; $subtotal = $subtotal + $st; $bd = $item['boni'] * $cost + $item['desc']; $bonidesc = $bonidesc + $bd; $amount = $amount + $st - $bd; $ice = DB::table('tax_rates')->select('rate')->where('name', '=', 'ice')->first(); if ($pr->ice == 1) { //caluclo ice bruto $iceBruto = $qty * ($pr->cc / 1000) * $ice->rate; $iceNeto = (int) $item['boni'] * ($pr->cc / 1000) * $ice->rate; $icetotal = $icetotal + ($iceBruto - $iceNeto); // $fiscal = $fiscal + ($amount - ($item['qty'] *($pr->cc/1000)*$ice->rate) ); } } $fiscal = $amount - $bonidesc - $icetotal; $balance = $amount; /////////////////////////hasta qui esta bien al parecer hacer prueba de que fuciona el join de los productos XD $invoice_dateCC = date("Ymd"); $invoice_date = date("Y-m-d"); $invoice_date_limitCC = date("Y-m-d", strtotime($branch->deadline)); // require_once(app_path().'/includes/control_code.php'); // $cod_control = codigoControl($invoice_number, $input['nit'], $invoice_dateCC, $amount, $branch->number_autho, $branch->key_dosage); $cod_control = $input['cod_control']; $ice = DB::table('tax_rates')->select('rate')->where('name', '=', 'ice')->first(); // // creando invoice $invoice = Invoice::createNew(); $invoice->invoice_number = $invoice_number; $invoice->client_id = $client_id; $invoice->user_id = $user_id; $invoice->account_id = $user->account_id; $invoice->branch_id = $user->branch_id; $invoice->amount = number_format((double) $amount, 2, '.', ''); $invoice->subtotal = $subtotal; $invoice->fiscal = $fiscal; $invoice->law = $branch->law; $invoice->balance = $balance; $invoice->control_code = $cod_control; $invoice->start_date = $invoice_date; $invoice->invoice_date = $invoice_date; $invoice->activity_pri = $branch->activity_pri; $invoice->activity_sec1 = $branch->activity_sec1; // $invoice->invoice $invoice->end_date = $invoice_date_limitCC; //datos de la empresa atra vez de una consulta XD /*****************error generado al intentar guardar **/ // $invoice->branch = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->number_autho = $branch->number_autho; $invoice->work_phone = $branch->postal_code; $invoice->city = $branch->city; $invoice->state = $branch->state; // $invoice->industry_id=$branch->industry_id; $invoice->country_id = $branch->country_id; $invoice->key_dosage = $branch->key_dosage; $invoice->deadline = $branch->deadline; $invoice->custom_value1 = $icetotal; $invoice->ice = $ice->rate; //cliente $invoice->nit = $input['nit']; $invoice->name = $input['name']; $invoice->save(); $account = Auth::user()->account; require_once app_path() . '/includes/BarcodeQR.php'; $ice = $invoice->amount - $invoice->fiscal; $desc = $invoice->subtotal - $invoice->amount; $amount = number_format($invoice->amount, 2, '.', ''); $fiscal = number_format($invoice->fiscal, 2, '.', ''); $icef = number_format($ice, 2, '.', ''); $descf = number_format($desc, 2, '.', ''); if ($icef == "0.00") { $icef = 0; } if ($descf == "0.00") { $descf = 0; } $qr = new BarcodeQR(); $datosqr = '1006909025|' . $input['invoice_number'] . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $amount . '|' . $fiscal . '|' . $invoice->nit . '|' . $icef . '|0|0|' . $descf; $qr->text($datosqr); $qr->draw(150, 'qr/' . $account->account_key . '_' . $invoice->invoice_number . '.png'); $input_file = 'qr/' . $account->account_key . '_' . $invoice->invoice_number . '.png'; $output_file = 'qr/' . $account->account_key . '_' . $invoice->invoice_number . '.jpg'; $inputqr = imagecreatefrompng($input_file); list($width, $height) = getimagesize($input_file); $output = imagecreatetruecolor($width, $height); $white = imagecolorallocate($output, 255, 255, 255); imagefilledrectangle($output, 0, 0, $width, $height, $white); imagecopy($output, $inputqr, 0, 0, 0, 0, $width, $height); imagejpeg($output, $output_file); $invoice->qr = HTML::image_data('qr/' . $account->account_key . '_' . $input['invoice_number'] . '.jpg'); $invoice->save(); $fecha = $input['fecha']; $f = date("Y-m-d", strtotime($fecha)); DB::table('invoices')->where('id', $invoice->id)->update(array('branch' => $branch->name, 'invoice_date' => $f)); //error verificar // $invoice = DB::table('invoices')->select('id')->where('invoice_number',$invoice_number)->first(); //guardadndo los invoice items foreach ($items as $item) { // $product = DB::table('products')->select('notes')->where('id',$product_id)->first(); $product_id = $item['id']; $product = DB::table('products')->join('prices', "product_id", "=", 'products.id')->select('products.id', 'products.notes', 'prices.cost', 'products.ice', 'products.units', 'products.cc', 'products.product_key')->where('prices.price_type_id', '=', $user->price_type_id)->where('products.account_id', '=', $user->account_id)->where('products.id', "=", $product_id)->first(); // $pr = DB::table('products')->select('cost')->where('id',$product_id)->first(); $cost = $product->cost / $product->units; $line_total = (int) $item['qty'] * $cost; $invoiceItem = InvoiceItem::createNew(); $invoiceItem->invoice_id = $invoice->id; $invoiceItem->product_id = $product_id; $invoiceItem->product_key = $product->product_key; $invoiceItem->notes = $product->notes; $invoiceItem->cost = $cost; $invoiceItem->boni = (int) $item['boni']; $invoiceItem->desc = $item['desc']; $invoiceItem->qty = (int) $item['qty']; $invoiceItem->line_total = $line_total; $invoiceItem->tax_rate = 0; $invoiceItem->save(); } // $invoiceItems =DB::table('invoice_items') // ->select('notes','cost','qty','boni','desc') // ->where('invoice_id','=',$invoice->id) // ->get(array('notes','cost','qty','boni','desc')); // $date = new DateTime($invoice->deadline); // $dateEmision = new DateTime($invoice->invoice_date); // $account = array('name' =>$branch->name,'nit'=>'1006909025' ); // $ice = $invoice->amount-$invoice->fiscal; // $factura = array('invoice_number' => $invoice->invoice_number, // 'control_code'=>$invoice->control_code, // 'invoice_date'=>$dateEmision->format('d-m-Y'), // 'amount'=>number_format((float)$invoice->amount, 2, '.', ''), // 'subtotal'=>number_format((float)$invoice->subtotal, 2, '.', ''), // 'fiscal'=>number_format((float)$invoice->fiscal, 2, '.', ''), // 'client'=>$client, // // 'id'=>$invoice->id, // 'account'=>$account, // 'law' => $invoice->law, // 'invoice_items'=>$invoiceItems, // 'address1'=>str_replace('+', '°', $invoice->address1), // // 'address2'=>str_replace('+', '°', $invoice->address2), // 'address2'=>$invoice->address2, // 'num_auto'=>$invoice->number_autho, // 'fecha_limite'=>$date->format('d-m-Y'), // // 'fecha_emsion'=>, // 'ice'=>number_format((float)$ice, 2, '.', '') // ); // $invoic = Invoice::scope($invoice_number)->withTrashed()->with('client.contacts', 'client.country', 'invoice_items')->firstOrFail(); // $d = Input::all(); //en caso de problemas irracionales me refiero a que se jodio // $input = Input::all(); // $client_id = $input['client_id']; // $client = DB::table('clients')->select('id','nit','name')->where('id',$input['client_id'])->first(); $datos = array('resultado ' => "0"); //colocar una excepcion en caso de error // return Response::json($datos); return Response::json($datos); }
/** * Return true if subscription can be changed * @param Invoice $invoice * @param BillingPlan $from * @param BillingPlan $to * @return boolean */ public function canUpgrade(InvoiceItem $item, ProductUpgrade $upgrade) { if ($item->billing_plan_id != $upgrade->from_billing_plan_id) { return false; } // check for other recurring items foreach ($this->getItems() as $it) { if ($item->invoice_item_id != $it->invoice_item_id) { if ((double) $it->second_total) { return false; } } // there is another recurring item, upgrade impossible } $to = $upgrade->getToPlan(); if (!$to) { return false; } // check if $to is compatible to billing terms $newItem = $this->createItem($to->getProduct()); $error = $this->isItemCompatible($newItem, array($item)); if (null != $error) { return false; } /* check if paysystem can do upgrade */ $pr = $item->tryLoadProduct(); if (!$pr instanceof Product) { return false; } $ps = $this->getPaysystem(); if (!$ps) { return false; } return $ps->canUpgrade($this, $item, $upgrade); }
/** * @param InvoiceItem $old * @param InvoiceItem $new * @return float old_price / new_price */ function compareDayCost(InvoiceItem $old, InvoiceItem $new) { // calculate difference in money // if both products have second_period we can compare prices $k = 1.0; foreach (array('second_', 'first_') as $k) { $period_o = $old->get($k . 'period'); $period_n = $new->get($k . 'period'); $price_o = (double) $old->get($k . 'price'); $price_n = (double) $new->get($k . 'price'); if (!$price_n || !$price_o || !$period_o || !$period_n) { continue; } if ($period_o == $period_n) { return round($price_o / $price_n, 4); } // else we need to recalculate both periods to days $po = new Am_Period($period_o); $pn = new Am_Period($period_n); $days_o = strtotime($po->addTo('2012-04-01') . ' 00:00:00') - strtotime('2012-04-01 00:00:00'); $days_o = intval($days_o / (3600 * 24)); $days_n = strtotime($pn->addTo('2012-04-01') . ' 00:00:00') - strtotime('2012-04-01 00:00:00'); $days_n = intval($days_n / (3600 * 24)); $price_o /= $days_o; $price_n /= $days_n; return round($price_o / $price_n, 4); } }
public function getLastSubscription() { return InvoiceItem::join('invoices', 'invoice_id', '=', 'invoices.id')->where('subscription_from', '<>', '0000-00-00 00:00:00')->where('invoices.user_id', $this->id)->orderBy('subscription_to', 'DESC')->select('subscription_from', 'subscription_to', 'subscription_hours_quota', 'invoice_id')->first(); }
public function invoice() { $items = PastTime::query()->whereIn('id', Input::get('items'))->where('invoice_id', 0)->orderBy('ressource_id', 'ASC')->orderBy('time_start', 'ASC')->get(); $lines = array(); $ressources = array(); $users = array(); $user = null; foreach ($items as $item) { $ressources[$item->ressource_id] = $item->ressource()->getResults(); $lines[$item->ressource_id][] = $item; $users[$item->user_id] = true; if (null == $user) { /** @var User $user */ $user = $item->user()->getResults(); } } if (count($users) > 1) { return Redirect::route('pasttime_list')->with('mError', 'Impossible de générer la facture pour plusieurs utilisateurs à la fois'); } if (count($users) == 0) { return Redirect::route('pasttime_list'); } $organisation = $user->organisations->first(); $invoice = new Invoice(); $invoice->user_id = $user->id; $invoice->created_at = new \DateTime(); $invoice->organisation_id = $organisation->id; $invoice->type = 'F'; $invoice->days = date('Ym'); $invoice->number = $invoice->next_invoice_number($invoice->type, $invoice->days); $invoice->address = $organisation->fulladdress; $invoice->date_invoice = new \DateTime(); $invoice->deadline = new \DateTime(date('Y-m-d', strtotime('+1 month'))); $invoice->save(); $vat = VatType::where('value', 20)->first(); $orderIndex = 0; foreach ($lines as $ressource_id => $line) { $ressource = $ressources[$ressource_id]; $invoice_line = new InvoiceItem(); $invoice_line->invoice_id = $invoice->id; $invoice_line->amount = 0; $invoice_line->order_index = $orderIndex++; if ($ressource_id == Ressource::TYPE_COWORKING) { $invoice_line->text = 'Coworking'; $sum_duration = 0; foreach ($line as $item) { $duration = ceil((strtotime($item->time_end) - strtotime($item->time_start)) / 3600 / self::COWORKING_HALF_DAY_MAX_DURATION); $sum_duration += $duration; $invoice_line->text .= sprintf("\n - %s de %s à %s (%s demi journée%s)", date('d/m/Y', strtotime($item->time_start)), date('H:i', strtotime($item->time_start)), date('H:i', strtotime($item->time_end)), $duration, $duration > 1 ? 's' : ''); $invoice_line->amount += $duration * (self::COWORKING_HALF_DAY_PRICING / 1.2); $item->invoice_id = $invoice->id; $item->save(); } $invoice_line->text .= sprintf("\nTotal : %s demi journée%s", $sum_duration, $sum_duration > 1 ? 's' : ''); } else { $invoice_line->text = sprintf('Location d\'espace de réunion - %s', $ressource->name); foreach ($line as $item) { $invoice_line->text .= sprintf("\n - %s de %s à %s", date('d/m/Y', strtotime($item->time_start)), date('H:i', strtotime($item->time_start)), date('H:i', strtotime($item->time_end))); $invoice_line->amount += min(7, (strtotime($item->time_end) - strtotime($item->time_start)) / 3600) * $ressource->amount; $item->invoice_id = $invoice->id; $item->save(); } } $invoice_line->vat_types_id = $vat->id; $invoice_line->ressource_id = $item->ressource_id; $invoice_line->save(); } return Redirect::route('invoice_modify', $invoice->id)->with('mSuccess', 'La facture a bien été générée'); }
protected function gridDiscountColumn($data, $row) { $criteria = new CDbCriteria(); $criteria->select = 'SUM(discount) as discount'; $criteria->condition = 'invoice_id= :invoiceId'; $criteria->params = array(':invoiceId' => $data->id); $product = InvoiceItem::model()->find($criteria); if ($product) { print_r($product->discount); } else { print_r(0); } }
/** * Add Invoice to the subscriptions * */ public function billSubscriptions() { $subscriptions = array(); foreach ($this->subscriptions as $subscription) { if ($subscription->getPaymentState() == $subscription::PAYMENT_OPEN || $subscription->getPaymentState() == $subscription::PAYMENT_RENEWAL && $subscription->getRenewalDate()->getTimestamp() <= time()) { $subscriptions[] = $subscription; } } if (empty($subscriptions)) { return; } //Create New Invoice $invoice = new Invoice(); foreach ($subscriptions as $subscription) { //Create New Invoice Item $invoiceItem = new InvoiceItem(); //Add InvoiceItem::$description to Subscription::getProductEntity() $invoiceItem->setDescription($subscription->getProduct()->getName() . ' (' . $subscription->getProductEntity() . ')'); //Add InvoiceItem::$price to Subscription::getPaymentAmount() $invoiceItem->setPrice($subscription->getPaymentAmount()); \Env::get('em')->persist($invoiceItem); //Attached to the created invoice $invoice->addInvoiceItem($invoiceItem); } $invoice->setOrder($this); \Env::get('em')->persist($invoice); //Attached to the order $this->addInvoice($invoice); }
private function importFilei() { $data = Session::get('data'); $map = Input::get('map'); $count = 0; $hasHeaders = true; foreach ($data as $row) { if ($hasHeaders) { $hasHeaders = false; continue; } foreach ($row as $index => $value) { $field = $map[$index]; $value = trim($value); if ($field == Invoice::$fieldCodClient) { $clients = Client::scope()->get(); $flag = 1; foreach ($clients as $client) { $cod_client = intval($value); if ($client->public_id == $cod_client) { $flag = 1; } } if ($flag == 0) { $message = 'cliente no encontrado ' . $value . 'Favor revisar el archivo importado '; Session::flash('message', $message); return Redirect::to('company/import_export'); } } else { if ($field == Invoice::$fieldProduct) { if ($value == '') { $message = 'Concepto vacío. Favor revisar el archivo importado '; Session::flash('message', $message); return Redirect::to('company/import_export'); } } else { if ($field == Invoice::$fieldAmount) { if ($value == '') { $message = 'Monto vacío. Favor revisar el archivo importado '; Session::flash('message', $message); return Redirect::to('company/import_export'); } } } } } } $branch_id = Input::get('branch_id'); $clients = Client::scope()->get(); $clientMap = []; $data = Session::get('data'); Session::forget('data'); $hasHeaders = true; foreach ($clients as $client) { $i = 0; $clientMap[$client->public_id][$i] = $client->id; $clientMap[$client->public_id][$i + 1] = $client->nit; $clientMap[$client->public_id][$i + 2] = $client->name; } foreach ($data as $row) { if ($hasHeaders) { $hasHeaders = false; continue; } $invoice = Invoice::createNew(); $invoiceItem = InvoiceItem::createNew(); $count++; $branch = \DB::table('branches')->where('id', $branch_id)->first(); $invoice->branch_id = $branch_id; $invoiceNumber = $branch->invoice_number_counter; $invoice->invoice_number = $invoiceNumber; $today = new DateTime('now'); $invoice->invoice_date = $today->format('Y-m-d'); $invoiceDesign = \DB::table('invoice_designs')->where('account_id', \Auth::user()->account_id)->orderBy('public_id', 'desc')->first(); $invoice->invoice_design_id = $invoiceDesign->id; $account = \Auth::user()->account; $invoice->account_name = $account->name; $invoice->account_nit = $account->nit; $invoice->branch_name = $branch->name; $invoice->address1 = $branch->address1; $invoice->address2 = $branch->address2; $invoice->phone = $branch->postal_code; $invoice->city = $branch->city; $invoice->state = $branch->state; $invoice->number_autho = $branch->number_autho; $invoice->deadline = $branch->deadline; $invoice->key_dosage = $branch->key_dosage; $invoice->activity_pri = $branch->activity_pri; $invoice->activity_sec1 = $branch->activity_sec1; $invoice->law = $branch->law; foreach ($row as $index => $value) { $field = $map[$index]; $value = trim($value); if ($field == Invoice::$fieldCodClient) { $cod_client = intval($value); $invoice->client_id = $clientMap[$cod_client][0]; $invoice->client_nit = $clientMap[$cod_client][1]; $invoice->client_name = $clientMap[$cod_client][2]; } else { if ($field == Invoice::$fieldProduct) { $notes = $value; } else { if ($field == Invoice::$fieldAmount) { $invoiceItem->notes = wordwrap($notes, 70, "\n"); $str = str_replace(".", "", $value); $amount = str_replace(",", ".", $str); $invoiceItem->cost = $amount; $invoiceItem->qty = 1; $invoiceItem->tax_rate = 0; $invoice->subtotal = $invoiceItem->cost; $invoice->amount = $invoiceItem->cost; $invoice->balance = $invoiceItem->cost; } } } } $invoice_dateCC = date("Ymd", strtotime($invoice->invoice_date)); $invoice_date_limitCC = date("d/m/Y", strtotime($branch->deadline)); require_once app_path() . '/includes/control_code.php'; $cod_control = codigoControl($invoice->invoice_number, $invoice->client_nit, $invoice_dateCC, $invoice->amount, $branch->number_autho, $branch->key_dosage); $invoice->control_code = $cod_control; $invoice_date = date("d/m/Y", strtotime($invoice->invoice_date)); require_once app_path() . '/includes/BarcodeQR.php'; // $ice = $invoice->amount-$invoice->fiscal; $desc = $invoice->subtotal - $invoice->amount; $subtotal = number_format($invoice->subtotal, 2, '.', ''); $amount = number_format($invoice->amount, 2, '.', ''); $fiscal = number_format($invoice->fiscal, 2, '.', ''); // $icef = number_format($ice, 2, '.', ''); $descf = number_format($desc, 2, '.', ''); // if($icef=="0.00"){ // $icef = 0; // } if ($descf == "0.00") { $descf = 0; } $icef = 0; $qr = new BarcodeQR(); $datosqr = $invoice->account_nit . '|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $subtotal . '|' . $amount . '|' . $invoice->control_code . '|' . $invoice->client_nit . '|' . $icef . '|0|0|' . $descf; $qr->text($datosqr); $qr->draw(150, 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'); $input_file = 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png'; $output_file = 'qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.jpg'; $inputqr = imagecreatefrompng($input_file); list($width, $height) = getimagesize($input_file); $output = imagecreatetruecolor($width, $height); $white = imagecolorallocate($output, 255, 255, 255); imagefilledrectangle($output, 0, 0, $width, $height, $white); imagecopy($output, $inputqr, 0, 0, 0, 0, $width, $height); imagejpeg($output, $output_file); $invoice->qr = HTML::image_data('qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.jpg'); $invoice->save(); $invoice->invoice_items()->save($invoiceItem); // Activity::createInvoice($invoice, false); } $message = Utils::pluralize('created_invoicei', $count); Session::flash('message', $message); return Redirect::to('invoices'); }
public function invoiceAction() { require_once APPLICATION_PATH . '/models/InvoiceItem.php'; $invoiceNo = $this->_getParam('invoiceNo'); $invItem = new InvoiceItem(); $items = $invItem->getItems($invoiceNo); $this->view->items = $items; $this->render('invoice'); }
public function calculate(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentAmount = 0.0, $paymentDate = 'now') { // take aff.commission_days in account for 1-tier only if ($tier == 0 && ($commissionDays = $this->getDi()->config->get('aff.commission_days'))) { $signupDays = $this->getDi()->time - strtotime($invoice->getUser()->added); $signupDays = intval($signupDays / 3600 * 24); // to days if ($commissionDays < $signupDays) { return; } // no commission for this case, affiliate<->user relation is expired // however, the relation still works for 2-level commissions } $multi = 1.0; $prefix = $paymentNumber == 0 ? 'first' : 'second'; if ($tier == 0) { if ($invoice->get("{$prefix}_total") == 0) { $paidForItem = 0; } else { $paidForItem = $paymentAmount * $item->get("{$prefix}_total") / $invoice->get("{$prefix}_total"); } } else { // for higher tier just take amount paid to previous tier $paidForItem = $paymentAmount; } foreach ($this->findRules($invoice, $item, $aff, $paymentNumber, $tier, $paymentDate) as $rule) { if ($rule->type == AffCommissionRule::TYPE_MULTI) { $multi *= $rule->multi; } else { if ($paidForItem == 0) { // free signup? if ($paymentNumber == 0 && $rule->free_signup_c) { return moneyRound($multi * $rule->free_signup_c); } } elseif ($paymentNumber == 0) { // first payment if ($rule->first_payment_t == '%') { return moneyRound($multi * $rule->first_payment_c * $paidForItem / 100); } else { return moneyRound($multi * $rule->first_payment_c); } } else { // first payment if ($rule->recurring_t == '%') { return moneyRound($multi * $rule->recurring_c * $paidForItem / 100); } else { return moneyRound($multi * $rule->recurring_c); } } } } }
/** * Update existing invoice * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->active_invoice->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_invoice->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $invoice_data = $this->request->post('invoice'); if (!is_array($invoice_data)) { $invoice_data = array('number' => $this->active_invoice->getNumber(), 'due_on' => $this->active_invoice->getDueOn(), 'issued_on' => $this->active_invoice->getIssuedOn(), 'currency_id' => $this->active_invoice->getCurrencyId(), 'comment' => $this->active_invoice->getComment(), 'company_id' => $this->active_invoice->getCompanyId(), 'company_address' => $this->active_invoice->getCompanyAddress(), 'project_id' => $this->active_invoice->getProjectId(), 'note' => $this->active_invoice->getNote(), 'language_id' => $this->active_invoice->getLanguageId()); if (is_foreachable($this->active_invoice->getItems())) { $invoice_data['items'] = array(); foreach ($this->active_invoice->getItems() as $item) { $invoice_data['items'][] = array('description' => $item->getDescription(), 'unit_cost' => $item->getUnitCost(), 'quantity' => $item->getQuantity(), 'tax_rate_id' => $item->getTaxRateId(), 'total' => $item->getTotal(), 'subtotal' => $item->getSubtotal(), 'time_record_ids' => $item->getTimeRecordIds()); } // foreach } // if } // if $invoice_notes = InvoiceNoteTemplates::findAll(); $invoice_item_templates = InvoiceItemTemplates::findAll(); $this->smarty->assign(array('invoice_data' => $invoice_data, 'invoice_item_templates' => $invoice_item_templates, 'tax_rates' => TaxRates::findAll(), 'invoice_notes' => $invoice_notes, 'original_note' => $this->active_invoice->getNote())); $cleaned_notes = array(); if (is_foreachable($invoice_notes)) { foreach ($invoice_notes as $invoice_note) { $cleaned_notes[$invoice_note->getId()] = $invoice_note->getContent(); } // foreach } // if js_assign('invoice_notes', $cleaned_notes); js_assign('original_note', $this->active_invoice->getNote()); $cleaned_item_templates = array(); if (is_foreachable($invoice_item_templates)) { foreach ($invoice_item_templates as $invoice_item_template) { $cleaned_item_templates[$invoice_item_template->getId()] = array('description' => $invoice_item_template->getDescription(), 'unit_cost' => $invoice_item_template->getUnitCost(), 'quantity' => $invoice_item_template->getQuantity(), 'tax_rate_id' => $invoice_item_template->getTaxRateId()); } // foreach } // if js_assign('invoice_item_templates', $cleaned_item_templates); js_assign('company_details_url', assemble_url('invoice_company_details')); js_assign('move_icon_url', get_image_url('move.gif')); if ($this->request->isSubmitted()) { $this->active_invoice->setAttributes($invoice_data); $invoice_company = Companies::findById(array_var($invoice_data, 'company_id', null)); $this->active_invoice->setCompanyName($invoice_company->getName()); $save = $this->active_invoice->save(); if ($save && !is_error($save)) { InvoiceItems::deleteByInvoice($this->active_invoice); $counter = 1; if (is_foreachable($invoice_data['items'])) { foreach ($invoice_data['items'] as $invoice_item_data) { $invoice_item = new InvoiceItem(); $invoice_item->setAttributes($invoice_item_data); $invoice_item->setInvoiceId($this->active_invoice->getId()); $invoice_item->setPosition($counter); $item_save = $invoice_item->save(); if ($item_save && !is_error($item_save)) { $invoice_item->setTimeRecordIds(array_var($invoice_item_data, 'time_record_ids', null)); $counter++; } else { $this->smarty->assign('errors', new ValidationErrors(array('items' => lang('Invoice items data is not valid. All descriptions are required and there need to be at least one unit with cost set per item!')))); } // if } // foreach flash_success('":number" has been updated', array('number' => $this->active_invoice->getName())); if ($this->active_invoice->isIssued()) { $invoice_company = $this->active_invoice->getCompany(); if (instance_of($invoice_company, 'Company') && $invoice_company->hasManagers()) { $this->redirectTo('invoice_notify', array('invoice_id' => $this->active_invoice->getId())); } // if } // if $this->redirectToUrl($this->active_invoice->getViewUrl()); } else { $this->smarty->assign('errors', $save); } // if } // if } // if }
} ?> <?php } ?> <tr style="display: none;"> <td><?php echo Yii::t('app', 'Payment Type'); ?> :</td> <td> <?php echo $form->dropDownList($model, 'payment_type', InvoiceItem::itemAlias('payment_type'), array('id' => 'payment_type_id')); ?> </td> </tr> <?php if ($count_payment == 0) { ?> <tr> <td colspan="2" style='text-align:right'> <?php echo $form->textFieldControlGroup($model, 'alt_payment_amount', array('class' => 'input-small text-right', 'id' => 'alt_payment_amount_id', 'data-url' => Yii::app()->createUrl('SaleItem/AddPayment/'), 'placeholder' => Yii::t('app', 'Payment Amount') . ' ' . '៛', 'prepend' => '៛')); ?>
public function run() { DB::table('DEMO_Invoice_Item')->delete(); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 1)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 1)); InvoiceItem::create(array('description' => 'Chai', 'category' => 'Beverages', 'unitCost' => 13.0, 'quantity' => 1, 'total' => 13.0, 'invoice' => 1)); InvoiceItem::create(array('description' => 'Chang', 'category' => 'Beverages', 'unitCost' => 14.0, 'quantity' => 1, 'total' => 14.0, 'invoice' => 1)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 1)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 1)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 2)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 2)); InvoiceItem::create(array('description' => 'Boston Crab Meat', 'category' => 'Seafood', 'unitCost' => 25, 'quantity' => 1, 'total' => 25.0, 'invoice' => 2)); InvoiceItem::create(array('description' => 'Chai', 'category' => 'Beverages', 'unitCost' => 13.0, 'quantity' => 1, 'total' => 13.0, 'invoice' => 2)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 3)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 3)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 3)); InvoiceItem::create(array('description' => 'Ikura', 'category' => 'Seafood', 'unitCost' => 34, 'quantity' => 1, 'total' => 34.0, 'invoice' => 3)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 3)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 4)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 4)); InvoiceItem::create(array('description' => 'Boston Crab Meat', 'category' => 'Seafood', 'unitCost' => 25, 'quantity' => 1, 'total' => 25.0, 'invoice' => 4)); InvoiceItem::create(array('description' => 'Ikura', 'category' => 'Seafood', 'unitCost' => 34, 'quantity' => 1, 'total' => 34.0, 'invoice' => 4)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 4)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 5)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 5)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 6)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 6)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 6)); InvoiceItem::create(array('description' => 'Chai', 'category' => 'Beverages', 'unitCost' => 13.0, 'quantity' => 1, 'total' => 13.0, 'invoice' => 7)); InvoiceItem::create(array('description' => 'Boston Crab Meat', 'category' => 'Seafood', 'unitCost' => 25, 'quantity' => 1, 'total' => 25.0, 'invoice' => 7)); InvoiceItem::create(array('description' => 'Ikura', 'category' => 'Seafood', 'unitCost' => 34, 'quantity' => 1, 'total' => 34.0, 'invoice' => 7)); InvoiceItem::create(array('description' => 'Chang', 'category' => 'Beverages', 'unitCost' => 14.0, 'quantity' => 1, 'total' => 14.0, 'invoice' => 7)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 8)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 8)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 8)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 8)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 8)); InvoiceItem::create(array('description' => 'Chai', 'category' => 'Beverages', 'unitCost' => 13.0, 'quantity' => 1, 'total' => 13.0, 'invoice' => 9)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 9)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 9)); InvoiceItem::create(array('description' => 'Ikura', 'category' => 'Seafood', 'unitCost' => 34, 'quantity' => 1, 'total' => 34.0, 'invoice' => 9)); InvoiceItem::create(array('description' => 'Chang', 'category' => 'Beverages', 'unitCost' => 14.0, 'quantity' => 1, 'total' => 14.0, 'invoice' => 9)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 10)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 10)); InvoiceItem::create(array('description' => 'Boston Crab Meat', 'category' => 'Seafood', 'unitCost' => 25, 'quantity' => 1, 'total' => 25.0, 'invoice' => 10)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 11)); InvoiceItem::create(array('description' => 'Chai', 'category' => 'Beverages', 'unitCost' => 13.0, 'quantity' => 1, 'total' => 13.0, 'invoice' => 11)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 12)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 12)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 13)); InvoiceItem::create(array('description' => 'Ikura', 'category' => 'Seafood', 'unitCost' => 34, 'quantity' => 1, 'total' => 34.0, 'invoice' => 13)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 13)); InvoiceItem::create(array('description' => 'Chai', 'category' => 'Beverages', 'unitCost' => 13.0, 'quantity' => 1, 'total' => 13.0, 'invoice' => 13)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 14)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 14)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 15)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 15)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 15)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 16)); InvoiceItem::create(array('description' => 'Boston Crab Meat', 'category' => 'Seafood', 'unitCost' => 25, 'quantity' => 1, 'total' => 25.0, 'invoice' => 16)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 16)); InvoiceItem::create(array('description' => 'Chang', 'category' => 'Beverages', 'unitCost' => 14.0, 'quantity' => 1, 'total' => 14.0, 'invoice' => 15)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 15)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 17)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 17)); InvoiceItem::create(array('description' => 'Shichimi', 'category' => 'Condiments', 'unitCost' => 5, 'quantity' => 1, 'total' => 5.0, 'invoice' => 17)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 17)); InvoiceItem::create(array('description' => 'Chang', 'category' => 'Beverages', 'unitCost' => 14.0, 'quantity' => 1, 'total' => 14.0, 'invoice' => 17)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 18)); InvoiceItem::create(array('description' => 'Boston Crab Meat', 'category' => 'Seafood', 'unitCost' => 25, 'quantity' => 1, 'total' => 25.0, 'invoice' => 18)); InvoiceItem::create(array('description' => 'Inlagd Sill', 'category' => 'Seafood', 'unitCost' => 18, 'quantity' => 1, 'total' => 18.0, 'invoice' => 19)); InvoiceItem::create(array('description' => 'Ipoh Coffee', 'category' => 'Beverages', 'unitCost' => 12.0, 'quantity' => 1, 'total' => 12.0, 'invoice' => 19)); InvoiceItem::create(array('description' => 'Chang', 'category' => 'Beverages', 'unitCost' => 14.0, 'quantity' => 1, 'total' => 14.0, 'invoice' => 19)); InvoiceItem::create(array('description' => 'Steeleye Stout', 'category' => 'Beverages', 'unitCost' => 11.0, 'quantity' => 1, 'total' => 11.0, 'invoice' => 20)); InvoiceItem::create(array('description' => 'Ikura', 'category' => 'Seafood', 'unitCost' => 34, 'quantity' => 1, 'total' => 34.0, 'invoice' => 20)); InvoiceItem::create(array('description' => 'Pesto genovese', 'category' => 'Condiments', 'unitCost' => 7, 'quantity' => 1, 'total' => 7.0, 'invoice' => 20)); }
?> <?php echo TbHtml::linkButton(Yii::t('app', 'Print Receipt'), array('id' => 'finish_sale_button', 'color' => TbHtml::BUTTON_COLOR_INFO, 'size' => TbHtml::BUTTON_SIZE_SMALL, 'icon' => 'glyphicon-off white', 'url' => Yii::app()->createUrl('SaleItem/CompleteSale/'), 'class' => 'complete-sale pull-right', 'title' => Yii::t('app', 'Complete Sale'))); ?> <?php } else { ?> <?php echo TbHtml::linkButton(Yii::t('app', 'Payment'), array('color' => TbHtml::BUTTON_COLOR_SUCCESS, 'size' => TbHtml::BUTTON_SIZE_SMALL, 'icon' => 'glyphicon-heart white', 'url' => Yii::app()->createUrl('SaleItem/AddPayment/'), 'class' => 'add-payment pull-right', 'title' => Yii::t('app', 'Add Payment'))); ?> <?php } ?> <div style="display: none;"> <?php echo $form->dropDownList($model, 'payment_type', InvoiceItem::itemAlias('payment_type'), array('class' => 'span3 pull-right', 'id' => 'payment_type_id')); ?> </div> <div class="pull-right"> <?php /*echo $form->textField($model,'payment_amount',array('class'=>'input-medium numpad','style'=>'text-align: right', 'maxlength'=>10,'id'=>'payment_amount_id','data-url'=>Yii::app()->createUrl('SaleItem/AddPayment/'), 'placeholder'=>Yii::t('app','Payment Amount'), )); */ ?> <?php echo $form->textField($model, 'payment_amount', array('class' => 'input-medium text-right payment-amount-txt numpad', 'id' => 'payment_amount_id', 'data-url' => Yii::app()->createUrl('SaleItem/AddPayment/'), 'placeholder' => Yii::t('app', 'Payment Amount') . ' ' . Yii::app()->settings->get('site', 'currencySymbol'))); ?> </div> <div class="pull-right"> </div>
function getInvoiceItems() { if (!$this->invoice_items) { $finder = new InvoiceItem(); $this->invoice_items = $finder->find(array('invoice_id' => $this->id)); } return $this->invoice_items; }