// you can define invoice on payment addition

This commit is contained in:
aFolletete committed 2011-12-14 18:42:50 +00:00
1 parent e38804f7c2
commit 16175b1561
5 files changed
+91 -42

No files matched your search

+19
View File
@@ -279,6 +279,7 @@
<th>{l s='Payment method'}</th> <th>{l s='Payment method'}</th>
<th style="width:15%">{l s='Transaction ID'}</th> <th style="width:15%">{l s='Transaction ID'}</th>
<th style="width:25%">{l s='Amount'}</th> <th style="width:25%">{l s='Amount'}</th>
<th style="width:15%">{l s='Invoice'}</th>
<th style="width:10%">&nbsp;</th> <th style="width:10%">&nbsp;</th>
</tr> </tr>
</thead> </thead>
@@ -289,6 +290,13 @@
<td>{$payment->payment_method}</td> <td>{$payment->payment_method}</td>
<td>{$payment->transaction_id}</td> <td>{$payment->transaction_id}</td>
<td>{displayPrice price=$payment->amount currency=$payment->id_currency}</td> <td>{displayPrice price=$payment->amount currency=$payment->id_currency}</td>
<td>
{if $payment->id_order_invoice}
#{Configuration::get('PS_INVOICE_PREFIX', $current_id_lang)}{'%06d'|sprintf:OrderInvoice::retrieveOneById($payment->id_order_invoice)->number}
{else}
{l s='No invoice'}
{/if}
</td>
<td></td> <td></td>
</tr> </tr>
{/foreach} {/foreach}
@@ -313,6 +321,17 @@
{/foreach} {/foreach}
</select> </select>
</td> </td>
<td>
{if sizeof($invoices_collection)}
<select name="payment_invoice">
{foreach from=$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> <td><input class="button" type="submit" name="submitAddPayment" value="Add" /></td>
</tr> </tr>
</tbody> </tbody>
+9 -1
View File
@@ -1065,6 +1065,12 @@ class OrderCore extends ObjectModel
SET `id_order_invoice` = '.(int)$order_invoice->id.' SET `id_order_invoice` = '.(int)$order_invoice->id.'
WHERE `id_order` = '.(int)$order_invoice->id_order); WHERE `id_order` = '.(int)$order_invoice->id_order);
// Update order payment
Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'order_payment`
SET `id_order_invoice` = '.(int)$order_invoice->id.'
WHERE `id_order` = '.(int)$order_invoice->id_order);
$this->invoice_date = $order_invoice->date_add; $this->invoice_date = $order_invoice->date_add;
$this->invoice_number = $order_invoice->number; $this->invoice_number = $order_invoice->number;
$this->update(); $this->update();
@@ -1313,12 +1319,14 @@ class OrderCore extends ObjectModel
* @param string $payment_transaction_id * @param string $payment_transaction_id
* @param Currency $currency * @param Currency $currency
* @param string $date * @param string $date
* @param OrderInvoice $order_invoice
* @return bool * @return bool
*/ */
public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null) public function addOrderPayment($amount_paid, $payment_method = null, $payment_transaction_id = null, $currency = null, $date = null, $order_invoice = null)
{ {
$order_payment = new OrderPayment(); $order_payment = new OrderPayment();
$order_payment->id_order = $this->id; $order_payment->id_order = $this->id;
$order_payment->id_order_invoice = (!is_null($order_invoice) ? $order_invoice->id : null);
$order_payment->id_currency = ($currency ? $currency->id : $this->id_currency); $order_payment->id_currency = ($currency ? $currency->id : $this->id_currency);
// we kept the currency rate for historization reasons // we kept the currency rate for historization reasons
$order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1); $order_payment->conversion_rate = ($currency ? $currency->conversion_rate : 1);
+54 -40
View File
@@ -381,54 +381,68 @@ class OrderInvoiceCore extends ObjectModel
); );
} }
/** /**
* Returns all the order invoice that match the date interval * Returns all the order invoice that match the date interval
* *
* @since 1.5 * @since 1.5
* @static * @static
* @param $date_from * @param $date_from
* @param $date_to * @param $date_to
* @return array collection of OrderInvoice * @return array collection of OrderInvoice
*/ */
public static function getByDateInterval($date_from, $date_to) public static function getByDateInterval($date_from, $date_to)
{ {
$order_invoice_list = Db::getInstance()->ExecuteS('SELECT oi.* $order_invoice_list = Db::getInstance()->ExecuteS('
FROM `'._DB_PREFIX_.'order_invoice` oi SELECT oi.*
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = oi.`id_order`) FROM `'._DB_PREFIX_.'order_invoice` oi
WHERE DATE_ADD(oi.date_add, INTERVAL -1 DAY) <= \''.pSQL($date_to).'\' LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = oi.`id_order`)
AND oi.date_add >= \''.pSQL($date_from).'\' WHERE DATE_ADD(oi.date_add, INTERVAL -1 DAY) <= \''.pSQL($date_to).'\'
'.Context::getContext()->shop->addSqlRestriction(). AND oi.date_add >= \''.pSQL($date_from).'\'
' ORDER BY oi.date_add ASC'); '.Context::getContext()->shop->addSqlRestriction().
' ORDER BY oi.date_add ASC
');
return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list); return ObjectModel::hydrateCollection('OrderInvoice', $order_invoice_list);
} }
/**
* @since 1.5
* @static
* @param $id_order_invoice
*/
public static function getCarrier($id_order_invoice)
{
$carrier = false;
if ($id_carrier = OrderInvoice::getCarrierId($id_order_invoice))
$carrier = new Carrier((int)$id_carrier);
return $carrier;
}
/** /**
* @since 1.5 * @since 1.5
* @static * @static
* @param $id_order_invoice * @param $id_order_invoice
*/ */
public static function getCarrier($id_order_invoice) public static function getCarrierId($id_order_invoice)
{ {
$carrier = false; $sql = 'SELECT `id_carrier`
if ($id_carrier = OrderInvoice::getCarrierId($id_order_invoice)) FROM `'._DB_PREFIX_.'order_carrier`
$carrier = new Carrier((int)$id_carrier); WHERE `id_order_invoice` = '.(int)$id_order_invoice;
return $carrier; return Db::getInstance()->getValue($sql);
} }
/** /**
* @since 1.5 * @static
* @static * @param $id
* @param $id_order_invoice * @return OrderInvoice
*/ */
public static function getCarrierId($id_order_invoice) public static function retrieveOneById($id)
{ {
$sql = 'SELECT `id_carrier` $order_invoice = new OrderInvoice($id);
FROM `'._DB_PREFIX_.'order_carrier` if (!Validate::isLoadedObject($order_invoice))
WHERE `id_order_invoice` = '.(int)$id_order_invoice; throw new PrestashopException('Can\'t load Order Invoice object for id: '.$id);
return $order_invoice;
return Db::getInstance()->getValue($sql); }
}
} }
+2
View File
@@ -29,6 +29,7 @@ class OrderPaymentCore extends ObjectModel
{ {
public $id_order; public $id_order;
public $id_currency; public $id_currency;
public $id_order_invoice;
public $amount; public $amount;
public $payment_method; public $payment_method;
public $conversion_rate; public $conversion_rate;
@@ -48,6 +49,7 @@ class OrderPaymentCore extends ObjectModel
'fields' => array( 'fields' => array(
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_order_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true), 'amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isPrice', 'required' => true),
'payment_method' => array('type' => self::TYPE_STRING, 'validate' => 'isName'), 'payment_method' => array('type' => self::TYPE_STRING, 'validate' => 'isName'),
'conversion_rate' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'), 'conversion_rate' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'),
+7 -1
View File
@@ -559,6 +559,10 @@ class AdminOrdersControllerCore extends AdminController
$order = new Order(Tools::getValue('id_order')); $order = new Order(Tools::getValue('id_order'));
$amount = str_replace(',', '.', Tools::getValue('payment_amount')); $amount = str_replace(',', '.', Tools::getValue('payment_amount'));
$currency = new Currency(Tools::getValue('payment_currency')); $currency = new Currency(Tools::getValue('payment_currency'));
if ($order->hasInvoice())
$order_invoice = new OrderInvoice(Tools::getValue('payment_invoice'));
else
$order_invoice = null;
if (!Validate::isLoadedObject($order)) if (!Validate::isLoadedObject($order))
$this->_errors[] = Tools::displayError('Order can\'t be found'); $this->_errors[] = Tools::displayError('Order can\'t be found');
elseif (!Validate::isPrice($amount)) elseif (!Validate::isPrice($amount))
@@ -569,11 +573,13 @@ class AdminOrdersControllerCore extends AdminController
$this->_errors[] = Tools::displayError('Transaction ID is invalid'); $this->_errors[] = Tools::displayError('Transaction ID is invalid');
elseif (!Validate::isLoadedObject($currency)) elseif (!Validate::isLoadedObject($currency))
$this->_errors[] = Tools::displayError('Currency is invalid'); $this->_errors[] = Tools::displayError('Currency is invalid');
elseif ($order->hasInvoice() && !Validate::isLoadedObject($order_invoice))
$this->_errors[] = Tools::displayError('Invoice is invalid');
elseif (!Validate::isDate(Tools::getValue('payment_date'))) elseif (!Validate::isDate(Tools::getValue('payment_date')))
$this->_errors[] = Tools::displayError('Date is invalid'); $this->_errors[] = Tools::displayError('Date is invalid');
else else
{ {
if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'))) if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'), $order_invoice))
$this->_errors[] = Tools::displayError('An error occured on adding of order payment'); $this->_errors[] = Tools::displayError('An error occured on adding of order payment');
else else
Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token); Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=4&token='.$this->token);