257 lines
8.8 KiB
PHP
257 lines
8.8 KiB
PHP
<?php
|
|
ini_set ( 'max_execution_time', 9999999999 );
|
|
ini_set ( 'memory_limit', - 1 );
|
|
|
|
$db = $GLOBALS ['db'];
|
|
|
|
if ($_GET ['ids'] != "") {
|
|
|
|
$moj_post = $_GET['ids'];
|
|
|
|
|
|
$files = [ ];
|
|
$i = 0;
|
|
|
|
|
|
foreach ( $moj_post as $moje_id ) {
|
|
unset ( $dane );
|
|
unset ( $ecmsale );
|
|
$query = "select so_id from ecmstockdocouts where so_id='" . $moje_id . "' and deleted=0";
|
|
|
|
$result = $db->query ( $query );
|
|
$dane = $db->fetchByAssoc ( $result );
|
|
|
|
$ecmsale = new EcmSale ();
|
|
$ecmsale->retrieve ( $moje_id );
|
|
|
|
if ($dane ['so_id'] == "") {
|
|
|
|
$positions = $ecmsale->getPositionList ( true );
|
|
|
|
$wz = new EcmStockDocOut ();
|
|
$wz->register_date = date ( 'd.m.Y' );
|
|
$wz->stock_id = $ecmsale->stock_id;
|
|
$wz->order_no = $ecmsale->parent_document_no;
|
|
$wz->currency_id = $ecmsale->currency_id;
|
|
$wz->delivery_date = $ecmsale->delivery_date;
|
|
$wz->parent_id = $ecmsale->parent_id;
|
|
$wz->parent_name = $ecmsale->parent_name;
|
|
$wz->created_by = $current_user->id;
|
|
$wz->assigned_user_id = $current_user->id;
|
|
$wz->parent_address_street = $ecmsale->parent_address_street;
|
|
$wz->parent_address_postalcode = $ecmsale->parent_address_postalcode;
|
|
$wz->parent_address_city = $ecmsale->parent_address_city;
|
|
$wz->parent_address_country = $ecmsale->parent_address_country;
|
|
$wz->parent_nip = $ecmsale->parent_nip;
|
|
$wz->parent_iln = $ecmsale->parent_iln;
|
|
$wz->currency_id = 'PLN';
|
|
$wz->category = 'wz_products';
|
|
|
|
$wz->shipping_address_name = $ecmsale->shipping_address_name;
|
|
$wz->shipping_address_postalcode = $ecmsale->shipping_address_postalcode;
|
|
$wz->shipping_address_city = $ecmsale->shipping_address_city;
|
|
$wz->shipping_address_country = $ecmsale->shipping_address_country;
|
|
$wz->shipping_address_street = $ecmsale->shipping_address_street;
|
|
$wz->shipping_nip = $ecmsale->shipping_nip;
|
|
$wz->shipping_iln = $ecmsale->shipping_iln;
|
|
$wz->position_list = $positions;
|
|
$wz->so_id = $ecmsale->id;
|
|
|
|
$wz->save ();
|
|
|
|
$files [] = createEcmStockDocOutPdf ( $wz->id, 'FILE' );
|
|
|
|
echo "Do zamówienia nr ZS " . $ecmsale->document_no . " został utworzony dokument WZ nr: <a href='index.php?module=EcmStockDocOuts&action=DetailView&record=" . $wz->id . "'>" . $wz->document_no . '</a><br>';
|
|
|
|
|
|
$invoice = new EcmInvoiceOut ();
|
|
|
|
$invoice->parent_id = $wz->parent_id;
|
|
$invoice->parent_name = $wz->parent_name;
|
|
$invoice->order_no = $wz->order_no;
|
|
// dates
|
|
$invoice->type = 'normal';
|
|
$invoice->stock_id = $wz->stock_id;
|
|
$invoice->register_date = date ( "d.m.Y" );
|
|
$invoice->sell_date = $wz->register_date;
|
|
|
|
$invoice->validtill_date = date ( "d.m.Y" );
|
|
|
|
$payment_date = new DateTime();
|
|
$payment_date->modify("+".$ecmsale->payment_date_days.' day');
|
|
$invoice->so_id = $ecmsale->id;
|
|
$invoice->payment_date = $payment_date->format("Y-m-d");
|
|
$invoice->payment_date_days = $ecmsale->payment_date_days;
|
|
// var_dump($ecmsale->payment_method);
|
|
$invoice->payment_method = 'PRZELEW';
|
|
$invoice->payment_method_paid = '0';
|
|
|
|
$invoice->parent_address_street = $ecmsale->parent_address_street;
|
|
$invoice->parent_address_postalcode = $ecmsale->parent_address_postalcode;
|
|
$invoice->parent_address_city = $ecmsale->parent_address_city;
|
|
$invoice->parent_address_country = $ecmsale->parent_address_country;
|
|
$invoice->parent_nip = $ecmsale->parent_nip;
|
|
$invoice->parent_iln = $ecmsale->parent_iln;
|
|
|
|
$invoice->parent_shipping_address_name = $ecmsale->shipping_address_name;
|
|
$invoice->parent_shipping_address_street = $ecmsale->shipping_address_street;
|
|
$invoice->parent_shipping_address_postalcode = $ecmsale->shipping_address_postalcode;
|
|
$invoice->parent_shipping_address_city = $ecmsale->shipping_address_city;
|
|
$invoice->parent_shipping_address_country = $ecmsale->shipping_address_country;
|
|
$invoice->parent_shipping_nip = $ecmsale->shipping_nip;
|
|
$invoice->parent_shipping_iln = $ecmsale->shipping_iln;
|
|
|
|
// saturn??
|
|
$tmp_a = new Account ();
|
|
$tmp_a->retrieve ( $wz->parent_id );
|
|
if ($tmp_a->parent_id == '1249') {
|
|
$a = new Account ();
|
|
$a->retrieve ( '1249' );
|
|
$invoice->supplier_code = '2503793';
|
|
$invoice->parent_payer_address_name = $a->name;
|
|
$invoice->parent_payer_address_street = $a->register_address_street;
|
|
$invoice->parent_payer_address_postalcode = $a->register_address_postalcode;
|
|
$invoice->parent_payer_address_city = $a->register_address_city;
|
|
$invoice->parent_payer_address_country = $a->register_address_country;
|
|
$invoice->parent_payer_nip = $a->to_vatid;
|
|
$invoice->parent_payer_iln = $a->iln;
|
|
|
|
$invoice->parent_address_street= 'Al. Jerozolimskie 179';
|
|
$invoice->parent_address_postalcode= '02-222';
|
|
$invoice->parent_address_city= 'Warszawa';
|
|
$invoice->parent_address_country= 'Polska';
|
|
|
|
}
|
|
$invoice->bankaccount=$tmp_a->invoice_bank_account ;
|
|
$invoice->pdf_text=$tmp_a->pdf_text;
|
|
if ($tmp_a->parent_id == '1249') {
|
|
$invoice->bankaccount=$a->invoice_bank_account ;
|
|
$invoice->pdf_text=$a->pdf_text;
|
|
}
|
|
$invoice->pdf_type = "K";
|
|
$invoice->currency_id = $ecmsale->currency_id;
|
|
$invoice->created_by = $current_user->id;
|
|
$invoice->assigned_user_id = $current_user->id;
|
|
$invoice->wz_id=$wz->id;
|
|
$invoice->wz_name=$wz->document_no;
|
|
|
|
|
|
$cenaz=$db->query("select * from ecmstockoperations where parent_id='".$wz->id."'");
|
|
$ceny=[];
|
|
while($cenyz=$db->fetchByAssoc($cenaz)){
|
|
$ceny[]=$cenyz['price'];
|
|
}
|
|
|
|
foreach ($positions as $key=>$position){
|
|
|
|
$positions[$key]['price_purchase']=$ceny[$key];
|
|
}
|
|
|
|
$invoice->position_list = $positions;
|
|
|
|
$invoice->save ();
|
|
|
|
$db->query("update ecminvoiceouts set purchase_price=(select sum(quantity*price) as total from ecmstockoperations where parent_id='".$wz->id."' and deleted=0) where id='".$invoice->id."'");
|
|
$files [] = createEcmInvoiceOutPdf ( $invoice->id, 'FILE' );
|
|
|
|
$query2 = "update ecmsales set status='s90' where id='" . $moje_id . "'";
|
|
|
|
$db->query ( $query2 );
|
|
|
|
echo "Do zamówienia nr ZS " . $ecmsale->document_no . " została utworzona faktura nr: <a href='index.php?module=EcmInvoiceOuts&action=DetailView&record=" . $invoice->id . "'>" . $invoice->document_no . '</a><br>';
|
|
|
|
} else {
|
|
echo "<span style='color:red'>UWAGA: Zamówienie nr: ZS " . $ecmsale->document_no . ' posiada już wystawiony dokument WZ!<br></span><br>';
|
|
}
|
|
$i++;
|
|
}
|
|
|
|
if (count ( $files ) > 0) {
|
|
|
|
unlink ( 'produkcja.pdf' );
|
|
include 'PDFMerger.php';
|
|
$pdf = new PDFMerger ();
|
|
foreach ( $files as $file ) {
|
|
$pdf->addPDF ( $file );
|
|
}
|
|
echo "Wygenerowano dokument zbiorczy, kliknij <a href='produkcja.pdf'>TUTAJ</a> aby pobrać!";
|
|
$pdf->merge ( "file", 'produkcja.pdf' );
|
|
die();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function createEcmStockDocOutPdf($record) {
|
|
include_once ("modules/EcmStockDocOuts/PDFTemplate/helper.php");
|
|
|
|
$focus = new EcmStockDocOut ();
|
|
$focus->retrieve ( $record );
|
|
|
|
$user = new User ();
|
|
$user->retrieve ( $focus->assigned_user_id );
|
|
|
|
include_once ("include/MPDF57/mpdf.php");
|
|
$p = new mPDF ( '', 'A4', null, 'helvetica', 10, 10, 30, 45, 5, 5 );
|
|
$labels = return_module_language ( $focus->ecmlanguage, 'EcmStockDocOuts' );
|
|
$mpdf->mirrorMargins = 1;
|
|
$db = $GLOBALS ['db'];
|
|
$positions = formatPDFPositions22 ( $focus->getPositionList ( true ), $focus );
|
|
$quantity = getQuantity22 ( $focus->getPositionList ( true ), $focus );
|
|
$content = '';
|
|
|
|
include ("modules/EcmStockDocOuts/PDFTemplate/content.php");
|
|
|
|
$ec = new EcmSysInfo ();
|
|
|
|
$footer = $ec->getFooterForModule ( 'EcmStockDocOuts' );
|
|
$header = $ec->getHeaderForModule ( 'EcmStockDocOuts' );
|
|
$p->SetHTMLHeader ( $header );
|
|
$p->SetHTMLFooter ( $footer );
|
|
$p->WriteHTML ( $content );
|
|
|
|
$EcmSysInfo = new EcmSysInfo ();
|
|
$dir = 'upload/' . $EcmSysInfo->getDatabaseName () . '/pdf/EcmStockDocOuts/';
|
|
if (! is_dir ( $dir )) {
|
|
mkdir ( $dir, '755', true );
|
|
}
|
|
$file_name = create_guid () . '.pdf';
|
|
$p->Output ( $dir . $file_name, "F" );
|
|
|
|
return $dir . $file_name;
|
|
}
|
|
function createEcmInvoiceOutPdf($record, $outputtype) {
|
|
$EcmInvoiceOut = new EcmInvoiceOut ();
|
|
$EcmInvoiceOut->retrieve ( $record );
|
|
$file_location = $EcmInvoiceOut->get_PDF_file_path ( '0' );
|
|
$EcmSysInfo = new EcmSysInfo ();
|
|
if ($EcmSysInfo->getDatabaseName () == 'preDb_60b08fe051546309b61d2714d4a0438d') {
|
|
$file_location = newPDFCreator ( $record, $type, true );
|
|
}
|
|
// return;
|
|
switch ($outputtype) {
|
|
case "BROSWER" :
|
|
header ( "Location: " . $file_location );
|
|
return true;
|
|
case "FILE" :
|
|
$path = $file_location;
|
|
break;
|
|
case "EMAIL" :
|
|
include_once 'include/ECM/EcmSendMail/EcmSendMail.inc';
|
|
$path = EcmSendMail::TEMP_DIR . 'ZS_' . $EcmInvoiceOut->number . '.pdf';
|
|
copy ( $file_location, $path );
|
|
|
|
break;
|
|
case "MULTIPDF" :
|
|
include_once 'include/ECM/EcmMultiPdf/EcmMultiPdf.inc';
|
|
$path = EcmMultiPdf::TEMP_DIR . 'EcmSales_' . $focus->id . '_' . create_guid () . '.pdf';
|
|
copy ( $file_location, $path );
|
|
break;
|
|
}
|
|
;
|
|
return $file_location;
|
|
}
|
|
?>
|