mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fix Invoice Create routes
This commit is contained in:
parent
92b46d5ed8
commit
c236925e6d
@ -42,6 +42,7 @@ class ClientSettings extends BaseSettings
|
||||
|
||||
public $language_id;
|
||||
public $currency_id;
|
||||
public $precision;
|
||||
public $default_task_rate;
|
||||
public $send_reminders;
|
||||
public $show_tasks_in_portal;
|
||||
|
@ -28,6 +28,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
public $language_id;
|
||||
public $currency_id;
|
||||
public $precision;
|
||||
public $show_currency_symbol;
|
||||
public $show_currency_code;
|
||||
|
||||
@ -136,6 +137,7 @@ class CompanySettings extends BaseSettings
|
||||
'timezone_id' => config('ninja.i18n.timezone_id'),
|
||||
'language_id' => config('ninja.i18n.language_id'),
|
||||
'currency_id' => config('ninja.i18n.currency_id'),
|
||||
'precision' => 2,
|
||||
'payment_terms' => config('ninja.i18n.payment_terms'),
|
||||
'datetime_format_id' => config('ninja.i18n.datetime_format'),
|
||||
'military_time' => config('ninja.i18n.military_time'),
|
||||
|
@ -15,7 +15,7 @@ use App\Models\CompanyLedger;
|
||||
|
||||
class CompanyLedgerFactory
|
||||
{
|
||||
public static function create(int $company_id, int $user_id) :Client
|
||||
public static function create(int $company_id, int $user_id) :CompanyLedger
|
||||
{
|
||||
$company_ledger = new CompanyLedger;
|
||||
$company_ledger->company_id = $company_id;
|
||||
|
@ -22,7 +22,7 @@ class InvoiceFactory
|
||||
{
|
||||
$invoice = new Invoice();
|
||||
$invoice->status_id = Invoice::STATUS_DRAFT;
|
||||
$invoice->invoice_number = '';
|
||||
$invoice->invoice_number = null;
|
||||
$invoice->discount = 0;
|
||||
$invoice->is_amount_discount = true;
|
||||
$invoice->po_number = '';
|
||||
|
@ -55,6 +55,9 @@ class InvoiceItemCalc
|
||||
private function setDiscount()
|
||||
{
|
||||
|
||||
if(!isset($this->item->is_amount_discount))
|
||||
return $this;
|
||||
|
||||
if($this->item->is_amount_discount)
|
||||
{
|
||||
$discount = $this->formatValue($this->item->discount, $this->settings->precision);
|
||||
@ -81,10 +84,10 @@ class InvoiceItemCalc
|
||||
{
|
||||
$item_tax = 0;
|
||||
|
||||
$tax_rate1 = $this->formatValue($this->item->tax_rate1, $this->settings->precision);
|
||||
|
||||
if($tax_rate1 != 0)
|
||||
if(isset($this->item->tax_rate1) && $this->item->tax_rate1 > 0)
|
||||
{
|
||||
$tax_rate1 = $this->formatValue($this->item->tax_rate1, $this->settings->precision);
|
||||
|
||||
if($this->settings->inclusive_taxes)
|
||||
$item_tax_rate1_total = $this->formatValue(($this->line_total - ($this->line_total / (1+$tax_rate1/100))) , $this->settings->precision);
|
||||
else
|
||||
@ -95,10 +98,10 @@ class InvoiceItemCalc
|
||||
$this->groupTax($this->item->tax_name1, $this->item->tax_rate1, $item_tax_rate1_total);
|
||||
}
|
||||
|
||||
$tax_rate2 = $this->formatValue($this->item->tax_rate2, $this->settings->precision);
|
||||
|
||||
if($tax_rate2 != 0)
|
||||
if(isset($this->item->tax_rate2) && $this->item->tax_rate2 > 0)
|
||||
{
|
||||
$tax_rate2 = $this->formatValue($this->item->tax_rate2, $this->settings->precision);
|
||||
|
||||
if($this->settings->inclusive_taxes)
|
||||
$item_tax_rate2_total = $this->formatValue(($this->line_total - ($this->line_total / (1+$tax_rate2/100))) , $this->settings->precision);
|
||||
else
|
||||
|
@ -30,20 +30,20 @@ class StoreInvoiceRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
$this->sanitize();
|
||||
//$this->sanitize();
|
||||
|
||||
return [
|
||||
'client_id' => 'required',
|
||||
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
||||
// 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/* If we have an email address instead of a client_id - harvest the client_id here
|
||||
public function sanitize()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
/** If we have an email address instead of a client_id - harvest the client_id here */
|
||||
|
||||
if(isset($input['email']) && !$input['client_id'])
|
||||
{
|
||||
$contact = ClientContact::company(auth()->user()->company()->id)->whereEmail($input['email'])->first();
|
||||
@ -59,7 +59,7 @@ public function sanitize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ class UpdateCompanyLedgerWithInvoice
|
||||
|
||||
public $adjustment;
|
||||
|
||||
public $invoice
|
||||
public $invoice;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -60,7 +60,7 @@ class UpdateCompanyLedgerWithInvoice
|
||||
$company_ledger->client_id = $this->invoice->client_id;
|
||||
$company_ledger->balance = $balance + $this->adjustment;
|
||||
$company_ledger->save();
|
||||
|
||||
|
||||
$this->invoice->company_ledger()->save($company_ledger);
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class StoreInvoice implements ShouldQueue
|
||||
$payment = false;
|
||||
|
||||
/* Test if we should auto-bill the invoice */
|
||||
if((bool)$invoice->settings->auto_bill)
|
||||
if((bool)$this->invoice->settings->auto_bill)
|
||||
{
|
||||
|
||||
$this->invoice = $invoice_repo->markSent($this->invoice);
|
||||
@ -109,5 +109,7 @@ class StoreInvoice implements ShouldQueue
|
||||
//fire invoice download and return PDF response from here
|
||||
}
|
||||
|
||||
return $this->invoice;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Repositories\ActivityRepository;
|
||||
@ -43,10 +44,10 @@ class CreateInvoiceActivity
|
||||
|
||||
$fields = new \stdClass;
|
||||
|
||||
$fields->client_id = $event->invoice->id;
|
||||
$fields->invoice_id = $event->invoice->id;
|
||||
$fields->user_id = $event->invoice->user_id;
|
||||
$fields->company_id = $event->invoice->company_id;
|
||||
$fields->activity_type_id = Activity::CREATE_INVOIE;
|
||||
$fields->activity_type_id = Activity::CREATE_INVOICE;
|
||||
|
||||
$this->activity_repo->save($fields, $event->invoice);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CompanyLedger extends BaseModel
|
||||
class CompanyLedger extends Model
|
||||
{
|
||||
|
||||
protected $dateFormat = 'Y-m-d H:i:s.u';
|
||||
|
@ -27,9 +27,34 @@ class Invoice extends BaseModel
|
||||
use NumberFormatter;
|
||||
use MakesDates;
|
||||
|
||||
protected $guarded = [
|
||||
'id',
|
||||
];
|
||||
protected $fillable = [
|
||||
'invoice_number',
|
||||
'discount',
|
||||
'po_number',
|
||||
'invoice_date',
|
||||
'due_date',
|
||||
'terms',
|
||||
'public_notes',
|
||||
'private_notes',
|
||||
'invoice_type_id',
|
||||
'tax_name1',
|
||||
'tax_rate1',
|
||||
'tax_name2',
|
||||
'tax_rate2',
|
||||
'is_amount_discount',
|
||||
'invoice_footer',
|
||||
'partial',
|
||||
'partial_due_date',
|
||||
'custom_value1',
|
||||
'custom_value2',
|
||||
'custom_taxes1',
|
||||
'custom_taxes2',
|
||||
'custom_text_value1',
|
||||
'custom_text_value2',
|
||||
'line_items',
|
||||
'settings',
|
||||
'client_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'settings' => 'object',
|
||||
|
@ -61,7 +61,7 @@ class InvoiceRepository extends BaseRepository
|
||||
$finished_amount = $invoice->amount;
|
||||
|
||||
if($finished_amount != $starting_amount)
|
||||
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice);
|
||||
UpdateCompanyLedgerWithInvoice::dispatchNow($invoice, ($finished_amount - $starting_amount));
|
||||
|
||||
return $invoice;
|
||||
|
||||
|
@ -160,8 +160,10 @@ class InvoiceTransformer extends EntityTransformer
|
||||
'has_expenses' => (bool) $invoice->has_expenses,
|
||||
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
|
||||
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
|
||||
'line_items' => $invoice->line_items,
|
||||
'backup' => $invoice->backup ?: '',
|
||||
'settings' => $invoice->settings,
|
||||
|
||||
];
|
||||
}
|
||||
}
|
@ -848,7 +848,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
});
|
||||
|
||||
Schema::create('company_ledger', function ($table) {
|
||||
Schema::create('company_ledgers', function ($table) {
|
||||
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('company_id');
|
||||
|
Loading…
x
Reference in New Issue
Block a user