add mutiple invoice generation for one csv

This commit is contained in:
Marion Muszynski 2017-06-16 10:59:02 +02:00
parent 59e7118dc7
commit 27b1222817
2 changed files with 63 additions and 1 deletions

View File

@ -24,7 +24,7 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
session_start();
define('PS_ADMIN_DIR', getcwd());
include(PS_ADMIN_DIR.'/../config/config.inc.php');
@ -52,6 +52,7 @@ $functionArray = array(
'privatesalesM3' => 'generateInvoicesPDFPrivateM3',
'privatesalesAll' => 'generateInvoicesPDFPrivateSalesAll',
'pendingorders' => 'generatePendingOrdersInvoice',
'privatesalesManyOrders' => 'generateManyInvoicesPDF',
);
foreach ($functionArray as $var => $function)
@ -61,6 +62,17 @@ foreach ($functionArray as $var => $function)
die;
}
function generateManyInvoicesPDF()
{
if (!isset($_SESSION['id_orders']))
die (Tools::displayError('Missing order ID'));
$orders = $_SESSION['id_orders'];
unset($_SESSION['id_orders']);
session_destroy();
PDF::multipleInvoices($orders, false, true, false, true);
}
function generateInvoicePDF()
{
if (!isset($_GET['id_order']))

View File

@ -241,6 +241,25 @@ class AdminAntConfigurations extends AdminTab
HelperFormBootstrap::displayWarning($this->l('Aucun résultat pour cette période'));
}
}
}elseif(Tools::isSubmit('submitOrderPdf')){
if(isset($_FILES['csvfile']) && $_FILES['csvfile']['name'] != '') {
$f = fopen($_FILES['csvfile']['tmp_name'], 'r');
fgetcsv($f, 0, ';');
$i = 1;
$orders = array();
while($line = fgetcsv($f, 0, ';')) {
$i++;
$orders[] = (int) $line[0];
}
if(!empty($orders)) {
session_start();
$_SESSION['id_orders'] = $orders;
Tools::redirectAdmin('pdf.php?privatesalesManyOrders&gift=1&token='.$this->token);
//PDF::multipleInvoices($orders, false, true, false, true);
}
}
}
}
@ -345,6 +364,9 @@ class AdminAntConfigurations extends AdminTab
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'loyalties'?'active':'').'">
<a href="#loyalties" aria-controls="loyalty" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-star-full"></span> '.$this->l('Suivi crédits fidélités').'</a>
</li>
<li role="presentation" class="'.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'invoices'?'active':'').'">
<a href="#invoices" aria-controls="loyalty" role="tab" data-toggle="tab"><span class="text-rose anticon anticon-file-pdf"></span> '.$this->l('Factures').'</a>
</li>
</ul>
<div class="tab-content">
@ -457,6 +479,34 @@ class AdminAntConfigurations extends AdminTab
</form>
</div>
</div>
<div role="tabpanel" class="tab-pane '.(Tools::getIsset('tab-pan') && Tools::getValue('tab-pan') == 'invoices'?'active':'').'" id="invoices">
<div class="panel-content">
<h3 class="">'.$this->l('Générer un PDF de plusieurs commandes').'</h3>
<br>
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&tab-pan=invoices" method="post" enctype="multipart/form-data">
<div class="col-md-6 col-md-offset-4">';
$help = '<br>
<p class="help-block">'.$this->l('Format: id_order').'</p>
<p class="help-block">'.$this->l('The subsequent columns and the first line are ignored.').'</p>
';
$input = array(
'type' => 'file',
'label' => $this->l('File:'),
'name' => 'csvfile',
'html' => $help
);
$form .= $helperForm->generateInput($input);
$form .= '
</div>
<div class="clearfix"></div>
<div class="ln_solid"></div>
<div class="form-group text-right">
<button type="submit" class="btn btn-primary" name="submitOrderPdf">'.$this->l('Générer PDF').'</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>