mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:44:29 -04:00
Merge fixes from develop
This commit is contained in:
parent
40241cbf38
commit
fc0a7cfbf0
@ -53,7 +53,7 @@ class ClientApiController extends BaseAPIController
|
|||||||
$query->where('email', $email);
|
$query->where('email', $email);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->listResponse($clients);
|
return $this->listResponse($clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,11 +112,13 @@ class ClientApiController extends BaseAPIController
|
|||||||
if ($request->action) {
|
if ($request->action) {
|
||||||
return $this->handleAction($request);
|
return $this->handleAction($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $request->input();
|
$data = $request->input();
|
||||||
$data['public_id'] = $publicId;
|
$data['public_id'] = $publicId;
|
||||||
$client = $this->clientRepo->save($data, $request->entity());
|
$client = $this->clientRepo->save($data, $request->entity());
|
||||||
|
|
||||||
|
$client->load(['contacts']);
|
||||||
|
|
||||||
return $this->itemResponse($client);
|
return $this->itemResponse($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,10 +148,10 @@ class ClientApiController extends BaseAPIController
|
|||||||
public function destroy(UpdateClientRequest $request)
|
public function destroy(UpdateClientRequest $request)
|
||||||
{
|
{
|
||||||
$client = $request->entity();
|
$client = $request->entity();
|
||||||
|
|
||||||
$this->clientRepo->delete($client);
|
$this->clientRepo->delete($client);
|
||||||
|
|
||||||
return $this->itemResponse($client);
|
return $this->itemResponse($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
'tax_name1',
|
'tax_name1',
|
||||||
'tax_rate1',
|
'tax_rate1',
|
||||||
'tax_name2',
|
'tax_name2',
|
||||||
'tax_rate2',
|
'tax_rate2',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_recurring' => 'boolean',
|
'is_recurring' => 'boolean',
|
||||||
'has_tasks' => 'boolean',
|
'has_tasks' => 'boolean',
|
||||||
@ -515,12 +515,12 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
'name',
|
'name',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->expenses as $expense) {
|
foreach ($this->expenses as $expense) {
|
||||||
$expense->setVisible([
|
$expense->setVisible([
|
||||||
'documents',
|
'documents',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($expense->documents as $document) {
|
foreach ($expense->documents as $document) {
|
||||||
$document->setVisible([
|
$document->setVisible([
|
||||||
'public_id',
|
'public_id',
|
||||||
@ -579,12 +579,12 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
|
|
||||||
return $schedule[1]->getStart();
|
return $schedule[1]->getStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDueDate($invoice_date = null){
|
public function getDueDate($invoice_date = null){
|
||||||
if(!$this->is_recurring) {
|
if(!$this->is_recurring) {
|
||||||
return $this->due_date ? $this->due_date : null;
|
return $this->due_date ? $this->due_date : null;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$now = time();
|
$now = time();
|
||||||
if($invoice_date) {
|
if($invoice_date) {
|
||||||
// If $invoice_date is specified, all calculations are based on that date
|
// If $invoice_date is specified, all calculations are based on that date
|
||||||
@ -598,7 +598,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
$now = $invoice_date->getTimestamp();
|
$now = $invoice_date->getTimestamp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->due_date && $this->due_date != '0000-00-00'){
|
if($this->due_date && $this->due_date != '0000-00-00'){
|
||||||
// This is a recurring invoice; we're using a custom format here.
|
// This is a recurring invoice; we're using a custom format here.
|
||||||
// The year is always 1998; January is 1st, 2nd, last day of the month.
|
// The year is always 1998; January is 1st, 2nd, last day of the month.
|
||||||
@ -607,7 +607,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
$monthVal = (int)date('n', $dueDateVal);
|
$monthVal = (int)date('n', $dueDateVal);
|
||||||
$dayVal = (int)date('j', $dueDateVal);
|
$dayVal = (int)date('j', $dueDateVal);
|
||||||
$dueDate = false;
|
$dueDate = false;
|
||||||
|
|
||||||
if($monthVal == 1) {// January; day of month
|
if($monthVal == 1) {// January; day of month
|
||||||
$currentDay = (int)date('j', $now);
|
$currentDay = (int)date('j', $now);
|
||||||
$lastDayOfMonth = (int)date('t', $now);
|
$lastDayOfMonth = (int)date('t', $now);
|
||||||
@ -634,7 +634,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
if($dueDay > $lastDayOfMonth){
|
if($dueDay > $lastDayOfMonth){
|
||||||
// No later than the end of the month
|
// No later than the end of the month
|
||||||
$dueDay = $lastDayOfMonth;
|
$dueDay = $lastDayOfMonth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dueDate = mktime(0, 0, 0, $dueMonth, $dueDay, $dueYear);
|
$dueDate = mktime(0, 0, 0, $dueMonth, $dueDay, $dueYear);
|
||||||
@ -663,7 +663,7 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
return date('Y-m-d', strtotime('+'.$days.' day', $now));
|
return date('Y-m-d', strtotime('+'.$days.' day', $now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't calculate one
|
// Couldn't calculate one
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -681,11 +681,11 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
$dateStart = $date->getStart();
|
$dateStart = $date->getStart();
|
||||||
$date = $this->account->formatDate($dateStart);
|
$date = $this->account->formatDate($dateStart);
|
||||||
$dueDate = $this->getDueDate($dateStart);
|
$dueDate = $this->getDueDate($dateStart);
|
||||||
|
|
||||||
if($dueDate) {
|
if($dueDate) {
|
||||||
$date .= ' <small>(' . trans('texts.due') . ' ' . $this->account->formatDate($dueDate) . ')</small>';
|
$date .= ' <small>(' . trans('texts.due') . ' ' . $this->account->formatDate($dueDate) . ')</small>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$dates[] = $date;
|
$dates[] = $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,16 +799,16 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
$invitation = $this->invitations[0];
|
$invitation = $this->invitations[0];
|
||||||
$link = $invitation->getLink('view', true);
|
$link = $invitation->getLink('view', true);
|
||||||
$key = env('PHANTOMJS_CLOUD_KEY');
|
$key = env('PHANTOMJS_CLOUD_KEY');
|
||||||
|
|
||||||
if (Utils::isNinjaDev()) {
|
if (Utils::isNinjaDev()) {
|
||||||
$link = env('TEST_LINK');
|
$link = env('TEST_LINK');
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
|
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
|
||||||
|
|
||||||
$pdfString = file_get_contents($url);
|
$pdfString = file_get_contents($url);
|
||||||
$pdfString = strip_tags($pdfString);
|
$pdfString = strip_tags($pdfString);
|
||||||
|
|
||||||
if ( ! $pdfString || strlen($pdfString) < 200) {
|
if ( ! $pdfString || strlen($pdfString) < 200) {
|
||||||
Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}");
|
Utils::logError("PhantomJSCloud - failed to create pdf: {$pdfString}");
|
||||||
return false;
|
return false;
|
||||||
@ -861,55 +861,55 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
return $total;
|
return $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if $calculatePaid is true we'll loop through each payment to
|
// if $calculatePaid is true we'll loop through each payment to
|
||||||
// determine the sum, otherwise we'll use the cached paid_to_date amount
|
// determine the sum, otherwise we'll use the cached paid_to_date amount
|
||||||
public function getTaxes($calculatePaid = false)
|
public function getTaxes($calculatePaid = false)
|
||||||
{
|
{
|
||||||
$taxes = [];
|
$taxes = [];
|
||||||
$taxable = $this->getTaxable();
|
$taxable = $this->getTaxable();
|
||||||
$paidAmount = $this->getAmountPaid($calculatePaid);
|
$paidAmount = $this->getAmountPaid($calculatePaid);
|
||||||
|
|
||||||
if ($this->tax_name1) {
|
if ($this->tax_name1) {
|
||||||
$invoiceTaxAmount = round($taxable * ($this->tax_rate1 / 100), 2);
|
$invoiceTaxAmount = round($taxable * ($this->tax_rate1 / 100), 2);
|
||||||
$invoicePaidAmount = $this->amount && $invoiceTaxAmount ? ($paidAmount / $this->amount * $invoiceTaxAmount) : 0;
|
$invoicePaidAmount = floatVal($this->amount) && $invoiceTaxAmount ? ($paidAmount / $this->amount * $invoiceTaxAmount) : 0;
|
||||||
$this->calculateTax($taxes, $this->tax_name1, $this->tax_rate1, $invoiceTaxAmount, $invoicePaidAmount);
|
$this->calculateTax($taxes, $this->tax_name1, $this->tax_rate1, $invoiceTaxAmount, $invoicePaidAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->tax_name2) {
|
if ($this->tax_name2) {
|
||||||
$invoiceTaxAmount = round($taxable * ($this->tax_rate2 / 100), 2);
|
$invoiceTaxAmount = round($taxable * ($this->tax_rate2 / 100), 2);
|
||||||
$invoicePaidAmount = $this->amount && $invoiceTaxAmount ? ($paidAmount / $this->amount * $invoiceTaxAmount) : 0;
|
$invoicePaidAmount = floatVal($this->amount) && $invoiceTaxAmount ? ($paidAmount / $this->amount * $invoiceTaxAmount) : 0;
|
||||||
$this->calculateTax($taxes, $this->tax_name2, $this->tax_rate2, $invoiceTaxAmount, $invoicePaidAmount);
|
$this->calculateTax($taxes, $this->tax_name2, $this->tax_rate2, $invoiceTaxAmount, $invoicePaidAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->invoice_items as $invoiceItem) {
|
foreach ($this->invoice_items as $invoiceItem) {
|
||||||
$itemTaxAmount = $this->getItemTaxable($invoiceItem, $taxable);
|
$itemTaxAmount = $this->getItemTaxable($invoiceItem, $taxable);
|
||||||
|
|
||||||
if ($invoiceItem->tax_name1) {
|
if ($invoiceItem->tax_name1) {
|
||||||
$itemTaxAmount = round($taxable * ($invoiceItem->tax_rate1 / 100), 2);
|
$itemTaxAmount = round($taxable * ($invoiceItem->tax_rate1 / 100), 2);
|
||||||
$itemPaidAmount = $this->amount && $itemTaxAmount ? ($paidAmount / $this->amount * $itemTaxAmount) : 0;
|
$itemPaidAmount = floatVal($this->amount) && $itemTaxAmount ? ($paidAmount / $this->amount * $itemTaxAmount) : 0;
|
||||||
$this->calculateTax($taxes, $invoiceItem->tax_name1, $invoiceItem->tax_rate1, $itemTaxAmount, $itemPaidAmount);
|
$this->calculateTax($taxes, $invoiceItem->tax_name1, $invoiceItem->tax_rate1, $itemTaxAmount, $itemPaidAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($invoiceItem->tax_name2) {
|
if ($invoiceItem->tax_name2) {
|
||||||
$itemTaxAmount = round($taxable * ($invoiceItem->tax_rate2 / 100), 2);
|
$itemTaxAmount = round($taxable * ($invoiceItem->tax_rate2 / 100), 2);
|
||||||
$itemPaidAmount = $this->amount && $itemTaxAmount ? ($paidAmount / $this->amount * $itemTaxAmount) : 0;
|
$itemPaidAmount = floatVal($this->amount) && $itemTaxAmount ? ($paidAmount / $this->amount * $itemTaxAmount) : 0;
|
||||||
$this->calculateTax($taxes, $invoiceItem->tax_name2, $invoiceItem->tax_rate2, $itemTaxAmount, $itemPaidAmount);
|
$this->calculateTax($taxes, $invoiceItem->tax_name2, $invoiceItem->tax_rate2, $itemTaxAmount, $itemPaidAmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $taxes;
|
return $taxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function calculateTax(&$taxes, $name, $rate, $amount, $paid)
|
private function calculateTax(&$taxes, $name, $rate, $amount, $paid)
|
||||||
{
|
{
|
||||||
if ( ! $amount) {
|
if ( ! $amount) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = round($amount, 2);
|
$amount = round($amount, 2);
|
||||||
$paid = round($paid, 2);
|
$paid = round($paid, 2);
|
||||||
$key = $rate . ' ' . $name;
|
$key = $rate . ' ' . $name;
|
||||||
|
|
||||||
if ( ! isset($taxes[$key])) {
|
if ( ! isset($taxes[$key])) {
|
||||||
$taxes[$key] = [
|
$taxes[$key] = [
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
@ -920,14 +920,14 @@ class Invoice extends EntityModel implements BalanceAffecting
|
|||||||
}
|
}
|
||||||
|
|
||||||
$taxes[$key]['amount'] += $amount;
|
$taxes[$key]['amount'] += $amount;
|
||||||
$taxes[$key]['paid'] += $paid;
|
$taxes[$key]['paid'] += $paid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasDocuments(){
|
public function hasDocuments(){
|
||||||
if(count($this->documents))return true;
|
if(count($this->documents))return true;
|
||||||
return $this->hasExpenseDocuments();
|
return $this->hasExpenseDocuments();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasExpenseDocuments(){
|
public function hasExpenseDocuments(){
|
||||||
foreach($this->expenses as $expense){
|
foreach($this->expenses as $expense){
|
||||||
if(count($expense->documents))return true;
|
if(count($expense->documents))return true;
|
||||||
|
@ -108,7 +108,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@if ($account->isPro())
|
@if ($account->hasFeature(FEATURE_DOCUMENTS))
|
||||||
<div clas="row">
|
<div clas="row">
|
||||||
<div class="col-md-2 col-sm-4"><div class="control-label" style="margin-bottom:10px;">{{trans('texts.expense_documents')}}</div></div>
|
<div class="col-md-2 col-sm-4"><div class="control-label" style="margin-bottom:10px;">{{trans('texts.expense_documents')}}</div></div>
|
||||||
<div class="col-md-12 col-sm-8">
|
<div class="col-md-12 col-sm-8">
|
||||||
@ -419,7 +419,7 @@
|
|||||||
function handleDocumentError() {
|
function handleDocumentError() {
|
||||||
window.countUploadingDocuments--;
|
window.countUploadingDocuments--;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user