gift management

This commit is contained in:
Marion Muszynski 2016-12-02 10:15:51 +01:00
parent e4921746e4
commit ed6002b84b
5 changed files with 430 additions and 172 deletions

View File

@ -109,9 +109,13 @@ function generateInvoicesPDFPrivateSales()
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
if(Tools::getValue('gift')){
PDF::multipleInvoices($orders, false, true, false, true);
} else {
PDF::multipleInvoices($orders, false, true);
}
}
}
}
function generateInvoicesPDFPrivateSales48h()
@ -179,9 +183,13 @@ function generateInvoicesPDFPrivateSalesAll()
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
if(Tools::getValue('gift')){
PDF::multipleInvoices($orders, false, true, false, true);
} else {
PDF::multipleInvoices($orders, false, true);
}
}
}
}
function generateInvoicesPDFPrivateMulti()
@ -248,9 +256,13 @@ function generateInvoicesPDFPrivateM2Plus()
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
if(Tools::getValue('gift')){
PDF::multipleInvoices($orders, false, true, false, true);
} else {
PDF::multipleInvoices($orders, false, true);
}
}
}
}

View File

@ -89,7 +89,7 @@ class AdminInvoices extends AdminTab
if($this->print_sales) {
echo '<form action="'.$currentIndex.'&token='.$this->token.'" method="post">
echo '<form id="form_admin_invoice" action="'.$currentIndex.'&token='.$this->token.'" method="post">
<table class="table" style="margin-top:30px; width: 100%">';
/*echo '
@ -124,8 +124,8 @@ class AdminInvoices extends AdminTab
echo '<tr class="'.$class.'">
<td align="center">'. $sale['id_sale'] .'</td>
<td><label for="multi_'.$sale['id_sale'].'" style="text-align: left; font-weight: normal">'. $sale['title'] .'<label></td>
<td>'. $date->format('Y-m-d') .'</td>';
<td><label for="multi_'.$sale['id_sale'].'" style="text-align: left; font-weight: bold">'. $sale['title'] .'<label></td>
<td align="center">'. $date->format('Y-m-d') .'</td>';
/*<td align="center">';
if ($sale['delivery_delay'] == 2
|| $sale['delivery_delay'] == 6) {
@ -149,8 +149,11 @@ class AdminInvoices extends AdminTab
echo '</td>*/
echo '</td>
<td align="center">
<a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<img src="../img/admin/pdf.gif" alt="">
<a title="Facture - Avec prix" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<span class="text-green-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
<a title="Facture cadeau - Sans prix" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&token='.$this->token.'">
<span class="text-rose anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</td>';
/*<td align="center">
@ -163,30 +166,37 @@ class AdminInvoices extends AdminTab
<td align="center"><input id="multi_plus_'. $sale['id_sale'].'" type="checkbox" name="multiPlus[]" value="'.$sale['id_sale'].'"/></td>
<td align="center">
<a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<img src="../img/admin/pdf.gif" alt="">
<span class="text-green-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
<a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&gift=1&token='.$this->token.'">
<span class="text-rose anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</td>
<td align="center" '.($sale['delivery_delay'] != 1?'style="background:#FFD3D3;"':'').'>'.(isset($sale['delivery_delay_name'])?$sale['delivery_delay_name']:'').'</td>
<td align="center" '.($sale['delivery_delay'] != 1?'style="background:#f49ac1;"':'').'>'.(isset($sale['delivery_delay_name'])?$sale['delivery_delay_name']:'').'</td>
</tr>';
}
// <td align="center"><input id="m2_'. $sale['id_sale'].'" type="checkbox" name="m2[]" value="'.$sale['id_sale'].'" /></td>
echo '<tr>
<td colspan="4">
<td colspan="4" style="padding:5px;">
<input type="hidden" name="date_to" value="'. Tools::getValue('date_to') .'" />
<input type="hidden" name="date_from" value="'. Tools::getValue('date_from') .'" />
<label style="float:none;" class="text-green-light "><span class="anticon anticon-file-pdf"></span> '.$this->l('Avec prix').'</label>
<label style="float:none;" class="text-rose "><span class="anticon anticon-file-pdf"></span> '.$this->l('Sans prix').'</label>
</td>';
/*<td align="center">
<input type="submit" name="submitPrintM2Bis" class="button" value="'.$this->l('Print M2\'').'" />
</td>*/
echo '<td align="center">
<input type="submit" name="submitPrintM2Plus" class="button" value="'.$this->l('Print M2+').'" />
<input type="submit" name="resetPrintM2Plus" class="button" value="'.$this->l('Unselect all').'" />
echo '<td align="center" style="padding:5px;">
<input type="submit" name="submitPrintM2Plus" class="btn btn-bbb btn-xs" value="'.$this->l('Print M2+').'" />
<input type="submit" name="resetPrintM2Plus" class="btn btn-bbb btn-xs" value="'.$this->l('Unselect all').'" />
</td>
<td align="center">
<input type="submit" name="submitPrintMPlus" class="button" value="'.$this->l('Print Même Marque').'" />
<td align="center" style="padding:5px;">
<input type="submit" name="submitPrintMPlus" class="btn btn-bbb btn-xs" value="'.$this->l('Print Même Marque').'" />
</td>
<td style="padding:5px;">
<p><label style="float:none;" class="text-purple"><input type="checkbox" name="gift" value="1" /> '.$this->l('Factures Cadeaux').'</label></p>
</td>
<td></td>
<td></td>
</tr>';
echo '</table>
@ -449,9 +459,13 @@ class AdminInvoices extends AdminTab
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts, FALSE, TRUE);
if(sizeof($orders)) {
if(Tools::getValue('gift') == 1) {
Tools::redirectAdmin('pdf.php?privatesalesAll&gift=1&id_sale='.(int) $sale->id.'&token='.$this->token);
} else {
Tools::redirectAdmin('pdf.php?privatesalesAll&id_sale='.(int) $sale->id.'&token='.$this->token);
}
}
}
$this->_errors[] = $this->l('No invoice found for this sale');
}
// print M1
@ -462,9 +476,13 @@ class AdminInvoices extends AdminTab
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts);
if(sizeof($orders)) {
if(Tools::getValue('gift') == 1) {
Tools::redirectAdmin('pdf.php?privatesales&gift=1&id_sale='.(int) $sale->id.'&token='.$this->token);
} else {
Tools::redirectAdmin('pdf.php?privatesales&id_sale='.(int) $sale->id.'&token='.$this->token);
}
}
}
$this->_errors[] = $this->l('No invoice found for this sale');
}
// print M2
@ -508,8 +526,12 @@ class AdminInvoices extends AdminTab
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'));
if(sizeof($orders)) {
if(Tools::getValue('gift') == 1) {
Tools::redirectAdmin('pdf.php?privatesalesM2Plus&gift=1&id_sale='.implode(',', $id_sales) .'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&token='.$this->token);
} else {
Tools::redirectAdmin('pdf.php?privatesalesM2Plus&id_sale='.implode(',', $id_sales) .'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&token='.$this->token);
}
}
$this->_errors[] = $this->l('No invoice found for these sales');
}
}
@ -524,8 +546,12 @@ class AdminInvoices extends AdminTab
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'));
if(sizeof($orders)) {
if(Tools::getValue('gift') == 1) {
Tools::redirectAdmin('pdf.php?privatesalesM2Plus&gift=1&id_sale='.implode(',', $id_sales) .'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&token='.$this->token);
} else {
Tools::redirectAdmin('pdf.php?privatesalesM2Plus&id_sale='.implode(',', $id_sales) .'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&token='.$this->token);
}
}
$this->_errors[] = $this->l('No invoice found for these sales');
}
}

View File

@ -329,14 +329,14 @@ class PDFCore extends PDF_PageGroupCore
$this->MultiCell(0.0, 4.0, $merchantDetailFooter, 0, 'C', 1);
}
public static function multipleInvoices($invoices, $multi = false, $tri = false, $expe48 = false)
public static function multipleInvoices($invoices, $multi = false, $tri = false, $expe48 = false, $gift = false)
{
$pdf = new PDF('P', 'mm', 'A4');
foreach ($invoices AS $id_order)
{
$orderObj = new Order((int)$id_order);
if (Validate::isLoadedObject($orderObj))
PDF::invoice($orderObj, 'D', true, $pdf, false, false, $multi, $tri, $expe48);
PDF::invoice($orderObj, 'D', true, $pdf, false, false, $multi, $tri, $expe48, $gift);
}
return $pdf->Output('invoices.pdf', 'D');
}
@ -564,12 +564,16 @@ class PDFCore extends PDF_PageGroupCore
* @param object $order Order
* @param string $mode Download or display (optional)
*/
public static function invoice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false, $multi = false, $tri = false, $expe48 = false)
public static function invoice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false, $multi = false, $tri = false, $expe48 = false, $gift = false)
{
global $cookie;
if (!Validate::isLoadedObject($order) OR (!$cookie->id_employee AND (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)))
die('Invalid order or invalid order state');
if($gift && $order->gift == 1) {
self::invoiceWithoutPrice($order, $mode = 'D', $multiple, $pdf, $slip, $delivery, $multi, $tri, $expe48);
} else {
self::$order = $order;
self::$orderSlip = $slip;
self::$delivery = $delivery;
@ -650,11 +654,11 @@ class PDFCore extends PDF_PageGroupCore
$pdf->Cell(0, 6, self::l('Invoice draft'), 1, 2, 'L', 1);
$pdf->Cell(55, 6, self::l('Order #').' '.sprintf('%06d', self::$order->id), 'L', 0);
$pdf->Cell(70, 6, self::l('Carrier:').($order->gift ? ' '.Tools::iconv('utf-8', self::encoding(), $carrier->name) : ''), 'L');
$pdf->Cell(70, 6, self::l('Carrier:'), 'L');
$pdf->Cell(0, 6, self::l('Payment method:'), 'LR');
$pdf->Ln(5);
$pdf->Cell(55, 6, (isset($shipping_date) ? self::l('Shipping date:').' '.Tools::displayDate($shipping_date, self::$order->id_lang) : ' '), 'LB', 0);
$pdf->Cell(70, 6, ($order->gift ? self::l('Gift-wrapped order') : Tools::iconv('utf-8', self::encoding(), $carrier->name)), 'LRB');
$pdf->Cell(70, 6, Tools::iconv('utf-8', self::encoding(), $carrier->name), 'LRB');
$pdf->Cell(0, 6, Tools::iconv('utf-8', self::encoding(), $order->payment), 'LRB');
$pdf->Ln(15);
$pdf->ProdTab((self::$delivery ? true : ''), $tri);
@ -788,6 +792,148 @@ class PDFCore extends PDF_PageGroupCore
if (!$multiple)
return $pdf->Output(sprintf('%06d', self::$order->id).'.pdf', $mode);
}
}
/**
* invoiceWithoutPrice
*
* @param object $order Order
* @param string $mode Download or display (optional)
*/
public static function invoiceWithoutPrice($order, $mode = 'D', $multiple = false, &$pdf = NULL, $slip = false, $delivery = false, $multi = false, $tri = false, $expe48 = false)
{
global $cookie;
if (!Validate::isLoadedObject($order) OR (!$cookie->id_employee AND (!OrderState::invoiceAvailable($order->getCurrentState()) AND !$order->invoice_number)))
die('Invalid order or invalid order state');
self::$order = $order;
self::$orderSlip = $slip;
self::$delivery = $delivery;
self::$_iso = strtoupper(Language::getIsoById((int)(self::$order->id_lang)));
if ((self::$_priceDisplayMethod = $order->getTaxCalculationMethod()) === false)
die(self::l('No price display method defined for the customer group'));
if (!$multiple)
$pdf = new PDF('P', 'mm', 'A4');
$pdf->SetAutoPageBreak(true, 35);
$pdf->StartPageGroup();
self::$currency = Currency::getCurrencyInstance((int)(self::$order->id_currency));
$pdf->AliasNbPages();
$pdf->AddPage();
$width = 100;
$pdf->SetX(10);
$pdf->SetY(25);
$pdf->SetFont(self::fontname(), '', 12);
$pdf->Cell($width, 10, self::l('Delivery'), 0, 'L');
$pdf->Cell($width, 10, self::l('Invoicing'), 0, 'L');
$pdf->Ln(5);
$pdf->SetFont(self::fontname(), '', 9);
$addressType = array(
'delivery' => array(),
'invoice' => array(),
);
$patternRules = array(
'optional' => array(
'address2',
'company'),
'avoid' => array(
'State:iso_code'));
$addressType = self::generateHeaderAddresses($pdf, $order, $addressType, $patternRules, $width);
if (Configuration::get('VATNUMBER_MANAGEMENT') AND !empty($addressType['invoice']['addressObject']->vat_number))
{
$vat_delivery = '';
if ($addressType['invoice']['addressObject']->id != $addressType['delivery']['addressObject']->id)
$vat_delivery = $addressType['delivery']['addressObject']->vat_number;
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $vat_delivery), 0, 'L');
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $addressType['invoice']['addressObject']->vat_number), 0, 'L');
$pdf->Ln(5);
}
if ($addressType['invoice']['addressObject']->dni != NULL)
$pdf->Cell($width, 10,
self::l('Tax ID number:').' '.Tools::iconv('utf-8', self::encoding(),
$addressType['invoice']['addressObject']->dni), 0, 'L');
/*
* display order information
*/
$carrier = new Carrier(self::$order->id_carrier);
if ($carrier->name == '0')
$carrier->name = Configuration::get('PS_SHOP_NAME');
$history = self::$order->getHistory(self::$order->id_lang);
foreach($history as $h)
if ($h['id_order_state'] == Configuration::get('PS_OS_SHIPPING'))
$shipping_date = $h['date_add'];
$pdf->Ln(12);
$pdf->SetFillColor(240, 240, 240);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont(self::fontname(), '', 9);
if (self::$orderSlip)
$pdf->Cell(0, 6, self::l('SLIP #').' '.sprintf('%06d', self::$orderSlip->id).' '.self::l('from') . ' ' .Tools::displayDate(self::$orderSlip->date_upd, self::$order->id_lang), 1, 2, 'L', 1);
elseif (self::$delivery)
$pdf->Cell(0, 6, self::l('DELIVERY SLIP #').Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_DELIVERY_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$delivery).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->delivery_date, self::$order->id_lang), 1, 2, 'L', 1);
elseif ((int)self::$order->invoice_date)
$pdf->Cell(0, 6, self::l('INVOICE #').' '.Tools::iconv('utf-8', self::encoding(), Configuration::get('PS_INVOICE_PREFIX', (int)($cookie->id_lang))).sprintf('%06d', self::$order->invoice_number).' '.self::l('from') . ' ' .Tools::displayDate(self::$order->invoice_date, self::$order->id_lang), 1, 2, 'L', 1);
else
$pdf->Cell(0, 6, self::l('Invoice draft'), 1, 2, 'L', 1);
$pdf->Cell(55, 6, self::l('Order #').' '.sprintf('%06d', self::$order->id), 'L', 0);
$pdf->Cell(70, 6, self::l('Carrier:'), 'L');
$pdf->Cell(0, 6, self::l('Payment method:'), 'LR');
$pdf->Ln(5);
$pdf->Cell(55, 6, (isset($shipping_date) ? self::l('Shipping date:').' '.Tools::displayDate($shipping_date, self::$order->id_lang) : ' '), 'LB', 0);
$pdf->Cell(70, 6, Tools::iconv('utf-8', self::encoding(), $carrier->name), 'LRB');
$pdf->Cell(0, 6, self::l('--'), 'LRB');
$pdf->Ln(15);
$pdf->ProdTab(true, $tri,true);
/* Canada */
$taxable_address = new Address((int)self::$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
if (!self::$delivery && strtoupper(Country::getIsoById((int)$taxable_address->id_country)) == 'CA')
{
$pdf->Ln(15);
$taxToDisplay = Db::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'order_tax WHERE id_order = '.(int)self::$order->id);
foreach ($taxToDisplay AS $t)
{
$pdf->Cell(0, 6, utf8_decode($t['tax_name']).' ('.number_format($t['tax_rate'], 2, '.', '').'%) '.self::convertSign(Tools::displayPrice($t['amount'], self::$currency, true)), 0, 0, 'R');
$pdf->Ln(5);
}
}
/* End */
/* Exit if delivery */
if (!self::$delivery)
{
if(!empty(self::$order->gift_message)) {
$pdf->Ln(15);
$pdf->SetFont(self::fontname(), 'B', 10);
$pdf->Cell(190, 0, Tools::iconv('utf-8', self::encoding(), self::$order->gift_message) , 0, 0, 'C');
}
if($multi) {
$pdf->Ln(15);
$pdf->SetFont(self::fontname(), 'B', 10);
$pdf->Cell(190, 0, Tools::iconv('utf-8', self::encoding(), 'Commande expédiée partiellement') , 0, 0, 'C');
}
if ($expe48) {
$pdf->Ln(15);
$pdf->SetFont(self::fontname(), '', 7);
$pdf->Cell(190, 0, Tools::iconv('utf-8', self::encoding(), 'Produit expédié sous 48h, si la commande comprend dautres articles, ceux-ci arriveront dans les délais indiqués lors de lachat') , 0, 0, 'L');
}
}
Hook::PDFInvoice($pdf, self::$order->id);
if (!$multiple)
return $pdf->Output(sprintf('%06d', self::$order->id).'.pdf', $mode);
}
public function ProdTabHeader($delivery = false)
{
@ -824,7 +970,7 @@ class PDFCore extends PDF_PageGroupCore
/**
* Product table with price, quantities...
*/
public function ProdTab($delivery = false)
public function ProdTab($delivery = false, $tri=false, $gift=false)
{
if (!$delivery)
$w = array(100, 15, 30, 15, 30);
@ -849,7 +995,7 @@ class PDFCore extends PDF_PageGroupCore
$line = 0;
foreach($products AS $product)
if (!$delivery OR ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded']) > 0))
if ((!$delivery || ($delivery && $gift)) || ((int)($product['product_quantity']) - (int)($product['product_quantity_refunded']) > 0))
{
if ($counter >= $lines)
{

View File

@ -3369,6 +3369,77 @@ a.link-anticon:hover{
color: #483e93!important;
}
/** button bootstrap */
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: 400;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
-ms-touch-action: manipulation;
touch-action: manipulation;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
.btn.focus, .btn:focus, .btn:hover {
color: #333;
text-decoration: none;
}
.btn-default {
color: #333;
background-color: #fff;
border-color: #ccc;
}
.btn-default:hover {
color: #333;
background-color: #e6e6e6;
border-color: #adadad;
}
.btn-default.focus,
.btn-default:focus {
color: #333;
background-color: #e6e6e6;
border-color: #8c8c8c;
}
.btn-bbb{
box-shadow: none;
text-align: center;
color: #504d8b;
border: 1px solid #ddd;
background-color: #fafafa;
font-size: 12px;
}
.btn-bbb:hover {
color: #504d8b;
background: #f4f4f4;
border-color: #8c8c8c;
}
.btn-bbb.focus,
.btn-bbb:focus {
color: #504d8b;
background: #f4f4f4;
border-color: #8c8c8c;
}
.btn-group-xs>.btn, .btn-xs {
padding: 1px 5px;
font-size: 12px;
line-height: 1.5;
border-radius: 3px;
}
button.btn, html input.btn{
cursor: pointer;
}
/** CustomerThread **/
form.form-subject-message{
width: 320px;
@ -3651,7 +3722,8 @@ form.form-forward-message .button:focus{
background-color: #F1F1F1;
}
#form_customer_thread table table,
.table.customerThread-table {
.table.customerThread-table,
#form_admin_invoice .table {
width: 100%;
border: 1px solid #565485;
background: #fff;
@ -3670,6 +3742,7 @@ form.form-forward-message .button:focus{
}
#form_customer_thread table table tr th,
.tab_customer_thread table tr th,
#form_admin_invoice .table tr th,
.table.customerThread-table tr th {
background: rgba(86,84,133,0.9);
color: #fff;
@ -3677,6 +3750,7 @@ form.form-forward-message .button:focus{
}
#form_customer_thread table table tr td,
.tab_customer_thread table tr td,
#form_admin_invoice .table tr td,
.table.customerThread-table tr td {
border-bottom: 1px solid #DEDEDE;
color: #000;

View File

@ -83,9 +83,9 @@ $(document).ready( function() {
var gift_fieldset = $('#gift_div').prev();
var gift_title = gift_fieldset.prev();
$('#gift_div, #gift_mobile_div').remove();
gift_fieldset.remove();
gift_title.remove();
// $('#gift_div, #gift_mobile_div').remove();
// gift_fieldset.remove();
// gift_title.remove();
{/literal}
{/if}