本文整理汇总了PHP中Invitation::createNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Invitation::createNew方法的具体用法?PHP Invitation::createNew怎么用?PHP Invitation::createNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Invitation
的用法示例。
在下文中一共展示了Invitation::createNew方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
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');
}
示例2: save
private function save($publicId = null)
{
$action = Input::get('action');
$entityType = Input::get('entityType');
if ($action == 'archive' || $action == 'delete' || $action == 'mark') {
return InvoiceController::bulk($entityType);
}
$input = json_decode(Input::get('data'));
$invoice = $input->invoice;
if (Utils::isAdmin()) {
$branch_id = $input->invoice->branch_id;
$branch = Branch::where('account_id', '=', Auth::user()->account_id)->where('public_id', $branch_id)->first();
// $branch = DB::table('branches')->where('id',$branch_id)->first();
} else {
$branch = Auth::user()->branch;
$branch_id = $branch->id;
$branch = DB::table('branches')->where('id', $branch_id)->first();
}
$today = new DateTime('now');
$today = $today->format('Y-m-d');
$datelimit = DateTime::createFromFormat('Y-m-d', $branch->deadline);
$datelimit = $datelimit->format('Y-m-d');
$valoresPrimera = explode("-", $datelimit);
$valoresSegunda = explode("-", $today);
$diaPrimera = $valoresPrimera[2];
$mesPrimera = $valoresPrimera[1];
$anyoPrimera = $valoresPrimera[0];
$diaSegunda = $valoresSegunda[2];
$mesSegunda = $valoresSegunda[1];
$anyoSegunda = $valoresSegunda[0];
$a = gregoriantojd($mesPrimera, $diaPrimera, $anyoPrimera);
$b = gregoriantojd($mesSegunda, $diaSegunda, $anyoSegunda);
$errorS = "Expiró la fecha límite de " . $branch->name;
if ($a - $b < 0) {
Session::flash('error', $errorS);
return Redirect::to("{$entityType}s/create")->withInput();
} else {
$last_invoice = Invoice::where('account_id', '=', Auth::user()->account_id)->first();
if ($last_invoice) {
$yesterday = $last_invoice->invoice_date;
$today = date("Y-m-d", strtotime($invoice->invoice_date));
$errorD = "La fecha de la factura es incorrecta";
$yesterday = new DateTime($yesterday);
$today = new DateTime($today);
if ($yesterday > $today) {
Session::flash('error', $errorD);
return Redirect::to("{$entityType}s/create")->withInput();
}
}
if ($errors = $this->invoiceRepo->getErrors($invoice)) {
Session::flash('error', trans('texts.invoice_error'));
return Redirect::to("{$entityType}s/create")->withInput()->withErrors($errors);
} else {
$this->taxRateRepo->save($input->tax_rates);
$clientData = (array) $invoice->client;
$clientData['branch'] = $branch->id;
$client = $this->clientRepo->save($invoice->client->public_id, $clientData);
$invoiceData = (array) $invoice;
$invoiceData['branch_id'] = $branch->id;
$invoiceData['client_id'] = $client->id;
$invoiceData['client_nit'] = $client->nit;
$invoiceData['client_name'] = $client->name;
$invoiceData['action'] = $action;
$invoice = $this->invoiceRepo->save($publicId, $invoiceData, $entityType);
$account = Auth::user()->account;
// if ($account->invoice_taxes != $input->invoice_taxes
// || $account->invoice_item_taxes != $input->invoice_item_taxes
// || $account->invoice_design_id != $input->invoice->invoice_design_id)
// {
// $account->invoice_taxes = $input->invoice_taxes;
// $account->invoice_item_taxes = $input->invoice_item_taxes;
// $account->invoice_design_id = $input->invoice->invoice_design_id;
// $account->save();
// }
$client->load('contacts');
$sendInvoiceIds = [];
foreach ($client->contacts as $contact) {
if ($contact->send_invoice || count($client->contacts) == 1) {
$sendInvoiceIds[] = $contact->id;
}
}
foreach ($client->contacts as $contact) {
$invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
$invitation = Invitation::createNew();
$invitation->invoice_id = $invoice->id;
$invitation->contact_id = $contact->id;
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
$invitation->save();
} else {
if (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
$invitation->delete();
}
}
}
$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, '.', '');
//.........这里部分代码省略.........
示例3: save
private function save($publicId = null)
{
$action = Input::get('action');
$entityType = Input::get('entityType');
if (in_array($action, ['archive', 'delete', 'mark', 'restore'])) {
return InvoiceController::bulk($entityType);
}
$input = json_decode(Input::get('data'));
$invoice = $input->invoice;
if ($errors = $this->invoiceRepo->getErrors($invoice)) {
Session::flash('error', trans('texts.invoice_error'));
return Redirect::to("{$entityType}s/create")->withInput()->withErrors($errors);
} else {
$this->taxRateRepo->save($input->tax_rates);
$clientData = (array) $invoice->client;
$client = $this->clientRepo->save($invoice->client->public_id, $clientData);
$invoiceData = (array) $invoice;
$invoiceData['client_id'] = $client->id;
$invoice = $this->invoiceRepo->save($publicId, $invoiceData, $entityType);
$account = Auth::user()->account;
if ($account->invoice_taxes != $input->invoice_taxes || $account->invoice_item_taxes != $input->invoice_item_taxes || $account->invoice_design_id != $input->invoice->invoice_design_id) {
$account->invoice_taxes = $input->invoice_taxes;
$account->invoice_item_taxes = $input->invoice_item_taxes;
$account->invoice_design_id = $input->invoice->invoice_design_id;
$account->save();
}
$client->load('contacts');
$sendInvoiceIds = [];
foreach ($client->contacts as $contact) {
if ($contact->send_invoice || count($client->contacts) == 1) {
$sendInvoiceIds[] = $contact->id;
}
}
foreach ($client->contacts as $contact) {
$invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
$invitation = Invitation::createNew();
$invitation->invoice_id = $invoice->id;
$invitation->contact_id = $contact->id;
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
$invitation->save();
} else {
if (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
$invitation->delete();
}
}
}
$message = trans($publicId ? "texts.updated_{$entityType}" : "texts.created_{$entityType}");
if ($input->invoice->client->public_id == '-1') {
$message = $message . ' ' . trans('texts.and_created_client');
$url = URL::to('clients/' . $client->public_id);
Utils::trackViewed($client->getDisplayName(), ENTITY_CLIENT, $url);
}
if ($action == 'clone') {
return $this->cloneInvoice($publicId);
} else {
if ($action == 'convert') {
return $this->convertQuote($publicId);
} else {
if ($action == 'email') {
if (Auth::user()->confirmed && !Auth::user()->isDemo()) {
$message = trans("texts.emailed_{$entityType}");
$this->mailer->sendInvoice($invoice);
Session::flash('message', $message);
} else {
$errorMessage = trans(Auth::user()->registered ? 'texts.confirmation_required' : 'texts.registration_required');
Session::flash('error', $errorMessage);
Session::flash('message', $message);
}
} else {
Session::flash('message', $message);
}
}
}
$url = "{$entityType}s/" . $invoice->public_id . '/edit';
return Redirect::to($url);
}
}
示例4: save
private function save($publicId = null)
{
$action = Input::get('action');
if ($action == 'archive' || $action == 'delete') {
return InvoiceController::bulk();
}
$input = json_decode(Input::get('data'));
$invoice = $input->invoice;
// if ($errors = $this->invoiceRepo->getErrors($invoice))
// {
// Session::flash('error', trans('texts.invoice_error'));
// return Redirect::to('invoices/create')
// ->withInput()->withErrors($errors);
// }
// else
// {
$this->taxRateRepo->save($input->tax_rates);
$clientData = (array) $invoice->client;
$client = $this->clientRepo->save($invoice->client->public_id, $clientData);
$invoiceData = (array) $invoice;
$invoiceData['client_id'] = $client->id;
$invoiceData['nit'] = $client->nit;
$invoiceData['name'] = $client->name;
$invoice = $this->invoiceRepo->save($publicId, $invoiceData);
$account = Auth::user()->account;
if ($account->invoice_taxes != $input->invoice_taxes || $account->invoice_item_taxes != $input->invoice_item_taxes || $account->invoice_design_id != $input->invoice->invoice_design_id) {
$account->invoice_taxes = $input->invoice_taxes;
$account->invoice_item_taxes = $input->invoice_item_taxes;
$account->invoice_design_id = $input->invoice->invoice_design_id;
$account->save();
}
$client->load('contacts');
$sendInvoiceIds = [];
foreach ($client->contacts as $contact) {
if ($contact->send_invoice || count($client->contacts) == 1) {
$sendInvoiceIds[] = $contact->id;
}
}
foreach ($client->contacts as $contact) {
$invitation = Invitation::scope()->whereContactId($contact->id)->whereInvoiceId($invoice->id)->first();
if (in_array($contact->id, $sendInvoiceIds) && !$invitation) {
$invitation = Invitation::createNew();
$invitation->invoice_id = $invoice->id;
$invitation->contact_id = $contact->id;
$invitation->invitation_key = str_random(RANDOM_KEY_LENGTH);
$invitation->save();
} else {
if (!in_array($contact->id, $sendInvoiceIds) && $invitation) {
$invitation->delete();
}
}
}
$branch = Auth::user()->branch;
$invoice_dateCC = date("Ymd", strtotime($invoice->invoice_date));
$invoice_date = date("d/m/Y", 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, $client->nit, $invoice_dateCC, $invoice->amount, $branch->number_autho, $branch->key_dosage);
$invoice->control_code = $cod_control;
$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;
$invoice->branch = $branch->name;
$invoice->address1 = $branch->address1;
$invoice->address2 = $branch->address2;
$invoice->work_phone = $branch->postal_code;
$invoice->city = $branch->city;
$invoice->state = $branch->state;
$invoice->save();
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|' . $invoice->invoice_number . '|' . $invoice->number_autho . '|' . $invoice_date . '|' . $amount . '|' . $fiscal . '|' . $invoice->control_code . '|' . $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 . '_' . $invoice->invoice_number . '.jpg');
$invoice->save();
//.........这里部分代码省略.........
示例5: fire
public function fire()
{
$this->info(date('Y-m-d') . ' Cargando 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) . ' facturas recurrentes encontradas');
foreach ($invoices as $recurInvoice) {
if ($recurInvoice->client->deleted_at) {
continue;
}
if (!$recurInvoice->user->confirmed) {
continue;
}
date_default_timezone_set($recurInvoice->account->getTimezone());
$this->info('Procesando la factura con el id ' . $recurInvoice->id . ($recurInvoice->shouldSendToday() ? ' si se enviará' : ' no se enviará'));
// if (!$recurInvoice->shouldSendToday())
// {
// continue;
// }
$branch_id = $recurInvoice->branch_id;
$branch = DB::table('branches')->where('id', $branch_id)->first();
$account_id = $recurInvoice->account_id;
$account = DB::table('accounts')->where('id', $account_id)->first();
if (strtotime($branch->deadline) < strtotime('now')) {
continue;
}
$invoice = Invoice::createNew($recurInvoice);
$invoice->client_id = $recurInvoice->client_id;
$invoice->recurring_invoice_id = $recurInvoice->id;
$invoice->branch_id = $recurInvoice->branch_id;
$invoiceNumber = $branch->invoice_number_counter;
$invoice->invoice_number = $branch->invoice_number_counter;
$invoice->amount = $recurInvoice->amount;
$invoice->subtotal = $recurInvoice->subtotal;
$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;
$invoice->account_name = $recurInvoice->account_name;
$invoice->account_nit = $recurInvoice->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->client_nit = $recurInvoice->client_nit;
$invoice->client_name = $recurInvoice->client_name;
$invoice->activity_pri = $branch->activity_pri;
$invoice->activity_sec1 = $branch->activity_sec1;
$invoice->law = $branch->law;
$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, 'public/qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png');
$input_file = 'public/qr/' . $account->account_key . '_' . $branch->name . '_' . $invoice->invoice_number . '.png';
$output_file = 'public/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');
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);
//.........这里部分代码省略.........