[*] BO : Improvement invoices management
This commit is contained in:
@@ -155,7 +155,7 @@
|
||||
<td>{dateFormat date=$row['date_add'] full=true}</td>
|
||||
<td><img src="../img/os/{$row['id_order_state']}.gif" /></td>
|
||||
<td>{$row['ostate_name']|stripslashes}</td>
|
||||
<td>{if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{/if}</td>
|
||||
<td>{if $row['employee_lastname']}{$row['employee_firstname']|stripslashes} {$row['employee_lastname']|stripslashes}{else} {/if}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
{/foreach}
|
||||
@@ -221,10 +221,11 @@
|
||||
<table class="table" width="100%;" cellspacing="0" cellpadding="0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:20%">Date</th>
|
||||
<th>Document</th>
|
||||
<th style="width:20%">Number</th>
|
||||
<th style="width:20px"></th>
|
||||
<th style="width:20%">{l s='Date'}</th>
|
||||
<th style="width:25%">{l s='Document'}</th>
|
||||
<th style="width:20%">{l s='Number'}</th>
|
||||
<th>{l s='Amount'}</th>
|
||||
<th style="width:42px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -233,10 +234,26 @@
|
||||
<td>{dateFormat date=$document->date_add}</td>
|
||||
<td>Invoice</td>
|
||||
<td><a href="pdf.php?pdf&id_order_invoice={$document->id}">#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$document->number}</a></td>
|
||||
<td><a href="#" onclick="jQuery('#invoiceNote{$document->id}').show(); return false;"><img src="../img/admin/comment_edit.png" alt="{l s='Edit'}" /></a></td>
|
||||
<td>
|
||||
{*if TYPE DOCUMENT = INVOICE *}
|
||||
{displayPrice price=$document->total_paid_tax_incl currency=$currency->id}
|
||||
{if $document->getRestPaid()}
|
||||
<span style="color:red;font-weight:bold;">({displayPrice price=$document->getRestPaid() currency=$currency->id} {l s='not paid'})</span>
|
||||
{/if}
|
||||
{*/if*}
|
||||
</td>
|
||||
<td class="right">
|
||||
{*if TYPE DOCUMENT = INVOICE *}
|
||||
{if $document->getRestPaid()}
|
||||
<a href="#" class="js-set-payment" data-amount="{$document->getRestPaid()}" data-id-invoice="{$document->id}"><img src="../img/admin/money_add.png" alt="{l s='Set payment form'}" /></a>
|
||||
{/if}
|
||||
<a href="#" onclick="$('#invoiceNote{$document->id}').show(); return false;"><img src="../img/admin/comment_edit.png" alt="{l s='Edit note'}" /></a>
|
||||
{*/if*}
|
||||
</td>
|
||||
</tr>
|
||||
{*if TYPE DOCUMENT = INVOICE *}
|
||||
<tr id="invoiceNote{$document->id}" style="display:none" class="current-edit">
|
||||
<td colspan="4">
|
||||
<td colspan="5">
|
||||
<form action="{$currentIndex}&viewOrder&id_order={$smarty.get.id_order|escape:'htmlall':'UTF-8'}&token={$smarty.get.token|escape:'htmlall':'UTF-8'}" method="post">
|
||||
<p>
|
||||
<label for="editNote{$document->id}" class="t">{l s='Note'}</label>
|
||||
@@ -245,14 +262,15 @@
|
||||
</p>
|
||||
<p class="right">
|
||||
<input type="submit" name="submitEditNote" value="{l s='Save'}" class="button" />
|
||||
<input type="button" name="cancelNote" id="cancelNote" value="{l s='Cancel'}" onclick="jQuery('#invoiceNote{$document->id}').hide();" class="button" />
|
||||
<input type="button" name="cancelNote" id="cancelNote" value="{l s='Cancel'}" onclick="$('#invoiceNote{$document->id}').hide();" class="button" />
|
||||
</p>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{*/if*}
|
||||
{foreachelse}
|
||||
<tr>
|
||||
<td colspan="4" class="center">
|
||||
<td colspan="5" class="center">
|
||||
<h3>{l s='No document is available'}</h3>
|
||||
<p><a class="button" href="{$currentIndex}&viewOrder&submitGenerateInvoice&id_order={$smarty.get.id_order|escape:'htmlall':'UTF-8'}&token={$smarty.get.token|escape:'htmlall':'UTF-8'}">{l s='Generate invoice'}</a></p>
|
||||
</td>
|
||||
@@ -288,7 +306,7 @@
|
||||
{l s='paid instead of'} <span class="total_paid">{displayPrice price=$order->total_paid_tax_incl currency=$currency->id}</span>
|
||||
</p>
|
||||
|
||||
<form method="post" action="{$currentIndex}&viewOrder&id_order={$smarty.get.id_order|escape:'htmlall':'UTF-8'}&token={$smarty.get.token|escape:'htmlall':'UTF-8'}">
|
||||
<form id="formAddPayment" method="post" action="{$currentIndex}&viewOrder&id_order={$smarty.get.id_order|escape:'htmlall':'UTF-8'}&token={$smarty.get.token|escape:'htmlall':'UTF-8'}">
|
||||
<table class="table" width="100%" cellspacing="0" cellpadding="0">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -317,40 +335,38 @@
|
||||
<td></td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
<tr>
|
||||
<td><input type="text" name="payment_date" class="datepicker" size="17" value="{date('Y-m-d H:i:s')}" /></td>
|
||||
<td>
|
||||
<select name="payment_method">
|
||||
{foreach from=PaymentModule::getInstalledPaymentModules() item=payment_method}
|
||||
{assign var=payment_name value=Module::getInstanceByName($payment_method.name)->displayName}
|
||||
<option value="{$payment_name}">{$payment_name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="payment_transaction_id" value="" />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="payment_amount" size="5" value="" />
|
||||
<select name="payment_currency">
|
||||
{foreach from=$currencies item=current_currency}
|
||||
<option value="{$current_currency['id_currency']}"{if $current_currency['id_currency'] == $currency->id} selected="selected"{/if}>{$current_currency['sign']}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
{if sizeof($invoices_collection)}
|
||||
{if count($not_paid_invoices_collection) > 0}
|
||||
<tr class="current-edit">
|
||||
<td><input type="text" name="payment_date" class="datepicker" size="17" value="{date('Y-m-d H:i:s')}" /></td>
|
||||
<td>
|
||||
<select name="payment_method">
|
||||
{foreach from=PaymentModule::getInstalledPaymentModules() item=payment_method}
|
||||
{assign var=payment_name value=Module::getInstanceByName($payment_method.name)->displayName}
|
||||
<option value="{$payment_name}">{$payment_name}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="payment_transaction_id" value="" />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="payment_amount" size="5" value="" />
|
||||
<select name="payment_currency">
|
||||
{foreach from=$currencies item=current_currency}
|
||||
<option value="{$current_currency['id_currency']}"{if $current_currency['id_currency'] == $currency->id} selected="selected"{/if}>{$current_currency['sign']}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select name="payment_invoice">
|
||||
{foreach from=$invoices_collection item=invoice}
|
||||
{foreach from=$not_paid_invoices_collection item=invoice}
|
||||
<option value="{$invoice->id}" selected="selected">#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:$invoice->number}</option>
|
||||
{/foreach}
|
||||
</select>
|
||||
{else}
|
||||
{l s='No invoice available'}
|
||||
{/if}
|
||||
</td>
|
||||
<td><input class="button" type="submit" name="submitAddPayment" value="Add" /></td>
|
||||
</tr>
|
||||
</td>
|
||||
<td><input class="button" type="submit" name="submitAddPayment" value="Add" /></td>
|
||||
</tr>
|
||||
{/if}
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
@@ -1397,6 +1397,20 @@ class OrderCore extends ObjectModel
|
||||
return $order_invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all not paid invoices for the current order
|
||||
* @since 1.5.0.2
|
||||
* @return Collection of Order invoice not paid
|
||||
*/
|
||||
public function getNotPaidInvoicesCollection()
|
||||
{
|
||||
$invoices = $this->getInvoicesCollection();
|
||||
foreach ($invoices as $key => $invoice)
|
||||
if ($invoice->isPaid())
|
||||
unset($invoices[$key]);
|
||||
return $invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total paid
|
||||
*
|
||||
|
||||
@@ -143,6 +143,28 @@ class OrderHistoryCore extends ObjectModel
|
||||
}
|
||||
}
|
||||
|
||||
// Set order as paid
|
||||
if ($newOS->paid == 1)
|
||||
{
|
||||
$invoices = $order->getInvoicesCollection();
|
||||
$payment_method = Module::getInstanceByName($order->module);
|
||||
foreach ($invoices as $invoice)
|
||||
{
|
||||
$rest_paid = $invoice->getRestPaid();
|
||||
if ($rest_paid)
|
||||
{
|
||||
$payment = new OrderPayment();
|
||||
$payment->id_order = $order->id;
|
||||
$payment->id_order_invoice = $invoice->id;
|
||||
$payment->id_currency = $order->id_currency;
|
||||
$payment->amount = $rest_paid;
|
||||
$payment->payment_method = $payment_method->displayName;
|
||||
$payment->conversion_rate = 1;
|
||||
$payment->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->id_order_state = (int)($new_order_state);
|
||||
|
||||
/* Change invoice number of order ? */
|
||||
|
||||
@@ -69,6 +69,9 @@ class OrderInvoiceCore extends ObjectModel
|
||||
/** @var intger */
|
||||
public $date_add;
|
||||
|
||||
/** @var array Total paid cache */
|
||||
protected static $_total_paid_cache = array();
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
@@ -449,4 +452,40 @@ class OrderInvoiceCore extends ObjectModel
|
||||
throw new PrestashopException('Can\'t load Order Invoice object for id: '.$id);
|
||||
return $order_invoice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Amounts of payments
|
||||
* @since 1.5.0.2
|
||||
* @return float Total paid
|
||||
*/
|
||||
public function getTotalPaid()
|
||||
{
|
||||
if (!array_key_exists($this->id, self::$_total_paid_cache))
|
||||
{
|
||||
self::$_total_paid_cache[$this->id] = 0;
|
||||
$payments = OrderPayment::getByInvoiceId($this->id);
|
||||
foreach ($payments as $payment)
|
||||
self::$_total_paid_cache[$this->id] += $payment->amount;
|
||||
}
|
||||
return self::$_total_paid_cache[$this->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rest Paid
|
||||
* @since 1.5.0.2
|
||||
* @return float Rest Paid
|
||||
*/
|
||||
public function getRestPaid()
|
||||
{
|
||||
return $this->total_paid_tax_incl - $this->getTotalPaid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.5.0.2
|
||||
* @return bool Is paid ?
|
||||
*/
|
||||
public function isPaid()
|
||||
{
|
||||
return $this->getTotalPaid() == $this->total_paid_tax_incl;
|
||||
}
|
||||
}
|
||||
@@ -81,8 +81,21 @@ class OrderPaymentCore extends ObjectModel
|
||||
{
|
||||
return Db::getInstance()->ExecuteS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'payment_order`
|
||||
FROM `'._DB_PREFIX_.'order_payment`
|
||||
WHERE `id_order` = '.(int)$id_order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Order Payments By Invoice ID
|
||||
* @static
|
||||
* @param $id_invoice Invoice ID
|
||||
* @return Collection Collection
|
||||
*/
|
||||
public static function getByInvoiceId($id_invoice)
|
||||
{
|
||||
$payments = new Collection('OrderPayment');
|
||||
$payments->where('a.id_order_invoice = '.(int)$id_invoice);
|
||||
return $payments;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,9 @@ class OrderStateCore extends ObjectModel
|
||||
/** @var boolean Shipped */
|
||||
public $shipped;
|
||||
|
||||
/** @var boolean Paid */
|
||||
public $paid;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
@@ -72,6 +75,7 @@ class OrderStateCore extends ObjectModel
|
||||
'unremovable' =>array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'delivery' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'hidden' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'paid' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
|
||||
// Lang fields
|
||||
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 64),
|
||||
|
||||
@@ -588,7 +588,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
else
|
||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||
}
|
||||
elseif (Tools::isSubmit('submitEditNote')) {
|
||||
elseif (Tools::isSubmit('submitEditNote'))
|
||||
{
|
||||
$id_order_invoice = (int)Tools::getValue('id_order_invoice');
|
||||
$note = Tools::getValue('note');
|
||||
$order_invoice = new OrderInvoice($id_order_invoice);
|
||||
@@ -829,6 +830,7 @@ class AdminOrdersControllerCore extends AdminController
|
||||
'can_edit' => ($this->tabAccess['edit'] == 1),
|
||||
'current_id_lang' => $this->context->language->id,
|
||||
'invoices_collection' => $order->getInvoicesCollection(),
|
||||
'not_paid_invoices_collection' => $order->getNotPaidInvoicesCollection(),
|
||||
'HOOK_INVOICE' => Hook::exec('invoice', array('id_order' => $order->id)),
|
||||
'HOOK_ADMIN_ORDER' => Hook::exec('adminOrder', array('id_order' => $order->id))
|
||||
);
|
||||
|
||||
@@ -283,6 +283,21 @@ class AdminStatusesControllerCore extends AdminController
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'paid',
|
||||
'values' => array(
|
||||
'query' => array(
|
||||
array(
|
||||
'id' => 'on',
|
||||
'name' => $this->l('Set order as paid'),
|
||||
'val' => '1'
|
||||
),
|
||||
),
|
||||
'id' => 'id',
|
||||
'name' => 'name'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'select_template',
|
||||
'label' => $this->l('Template:'),
|
||||
@@ -311,7 +326,8 @@ class AdminStatusesControllerCore extends AdminController
|
||||
'invoice_on' => $this->getFieldValue($obj, 'invoice'),
|
||||
'hidden_on' => $this->getFieldValue($obj, 'hidden'),
|
||||
'send_email_on' => $this->getFieldValue($obj, 'send_email'),
|
||||
'shipped_on' => $this->getFieldValue($obj, 'shipped')
|
||||
'shipped_on' => $this->getFieldValue($obj, 'shipped'),
|
||||
'paid_on' => $this->getFieldValue($obj, 'paid')
|
||||
);
|
||||
|
||||
return parent::renderForm();
|
||||
@@ -491,6 +507,7 @@ class AdminStatusesControllerCore extends AdminController
|
||||
$_POST['send_email'] = (int)Tools::getValue('send_email_on');
|
||||
$_POST['hidden'] = (int)Tools::getValue('hidden_on');
|
||||
$_POST['shipped'] = (int)Tools::getValue('shipped_on');
|
||||
$_POST['paid'] = (int)Tools::getValue('paid_on');
|
||||
if (!$_POST['send_email'])
|
||||
{
|
||||
$languages = Language::getLanguages(false);
|
||||
|
||||
@@ -1234,6 +1234,7 @@ CREATE TABLE `PREFIX_order_state` (
|
||||
`logable` tinyint(1) NOT NULL default '0',
|
||||
`delivery` tinyint(1) UNSIGNED NOT NULL default '0',
|
||||
`shipped` tinyint(1) UNSIGNED NOT NULL default '0',
|
||||
`paid` tinyint(1) UNSIGNED NOT NULL default '0',
|
||||
PRIMARY KEY (`id_order_state`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
@@ -364,9 +364,9 @@ INSERT INTO `PREFIX_category` (`id_category`, `id_parent`, `level_depth`, `nleft
|
||||
INSERT INTO `PREFIX_category_lang` (`id_category`, `id_lang`, `name`, `description`, `link_rewrite`, `meta_title`, `meta_keywords`, `meta_description`) VALUES
|
||||
(1, 1, 'Home', '', 'home', NULL, NULL, NULL),(1, 2, 'Accueil', '', 'home', NULL, NULL, NULL),(1, 3, 'Inicio', '', 'home', NULL, NULL, NULL),(1, 4, 'Start', '', 'home', NULL, NULL, NULL),(1, 5, 'Home page', '', 'home', NULL, NULL, NULL);
|
||||
|
||||
INSERT INTO `PREFIX_order_state` (`id_order_state`, `invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`, `shipped`) VALUES
|
||||
(1, 0, 1, 'RoyalBlue', 1, 0, 0, 0),(2, 1, 1, 'LimeGreen', 1, 1, 0, 0),(3, 1, 1, 'DarkOrange', 1, 1, 1, 0),(4, 1, 1, 'BlueViolet', 1, 1, 1, 1),(5, 1, 0, '#108510', 1, 1, 1, 1),
|
||||
(6, 0, 1, 'Crimson', 1, 0, 0, 0),(7, 1, 1, '#ec2e15', 1, 0, 0, 0),(8, 0, 1, '#8f0621', 1, 0, 0, 0),(9, 1, 1, 'HotPink', 1, 0, 0, 0),(10, 0, 1, 'RoyalBlue', 1, 0, 0, 0),(11, 0, 0, 'RoyalBlue', 1, 0, 0, 0),(12, 1, 0, 'LimeGreen', 1, 1, 0, 0);
|
||||
INSERT INTO `PREFIX_order_state` (`id_order_state`, `invoice`, `send_email`, `color`, `unremovable`, `logable`, `delivery`, `shipped`, `paid`) VALUES
|
||||
(1, 0, 1, 'RoyalBlue', 1, 0, 0, 0, 0),(2, 1, 1, 'LimeGreen', 1, 1, 0, 0, 1),(3, 1, 1, 'DarkOrange', 1, 1, 1, 0, 1),(4, 1, 1, 'BlueViolet', 1, 1, 1, 1, 1),(5, 1, 0, '#108510', 1, 1, 1, 1, 1),
|
||||
(6, 0, 1, 'Crimson', 1, 0, 0, 0, 0),(7, 1, 1, '#ec2e15', 1, 0, 0, 0, 0),(8, 0, 1, '#8f0621', 1, 0, 0, 0, 0),(9, 1, 1, 'HotPink', 1, 0, 0, 0, 1),(10, 0, 1, 'RoyalBlue', 1, 0, 0, 0, 0),(11, 0, 0, 'RoyalBlue', 1, 0, 0, 0, 0),(12, 1, 0, 'LimeGreen', 1, 1, 0, 0, 1);
|
||||
|
||||
INSERT INTO `PREFIX_order_state_lang` (`id_order_state`, `id_lang`, `name`, `template`) VALUES
|
||||
(1, 1, 'Awaiting cheque payment', 'cheque'),
|
||||
|
||||
@@ -47,6 +47,10 @@ ALTER TABLE `PREFIX_suplier` ADD COLUMN `id_address` int(10) unsigned NOT NULL A
|
||||
ALTER TABLE `PREFIX_address` ADD COLUMN `id_warehouse` int(10) unsigned NOT NULL DEFAULT 0 AFTER `id_supplier`;
|
||||
ALTER TABLE `PREFIX_order_invoice` ADD `note` TEXT NOT NULL AFTER `total_wrapping_tax_incl`;
|
||||
|
||||
/* ORDER STATES */
|
||||
ALTER TABLE `PREFIX_order_state` ADD `paid` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `shipped`;
|
||||
UPDATE `PREFIX_order_state` SET `paid` = 1 WHERE `id_order_state` IN (2, 3, 4, 5, 9, 12);
|
||||
|
||||
/************************
|
||||
* STOCK MANAGEMENT
|
||||
*************************/
|
||||
|
||||
@@ -478,6 +478,17 @@ $(document).ready(function() {
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.js-set-payment').click(function() {
|
||||
var amount = $(this).attr('data-amount');
|
||||
$('input[name=payment_amount]').val(amount);
|
||||
var id_invoice = $(this).attr('data-id-invoice');
|
||||
$('select[name=payment_invoice] option[value='+id_invoice+']').attr('selected', true);
|
||||
|
||||
$.scrollTo('#formAddPayment', 1000);
|
||||
|
||||
return false;
|
||||
})
|
||||
});
|
||||
|
||||
function addProductRefreshTotal()
|
||||
|
||||
Reference in New Issue
Block a user