Cześć,
wt., 7 sty 2020 o 10:55 Internet internety@jpk.pl napisał(a):
nie ma czegoś takiego jak zbiorcza faktura korygująca. Każda faktura
musi mieć "swoją" korektę.
W sensie jeśli chcesz wystawić wiele korekt, bo np wystawiali 'ZW' a potrzeba 'NP' (komuś się zamarzyło odzyskiwać VAT, sprzedaż ubezpieczeń) to można to sobie takim np php ogarnąć:
tylko to taxid sztywno i data 2013 rok zrobiłem - oczywiście powstało N (duże N, ponad 20) korekt, może komuś się przyda:
<?php
/* * LMS version 1.11.10 Kri
* $Id: invoicenote.php,v 1.42 2010/03/11 13:07:46 alec Exp $ */
$taxeslist = $LMS->GetTaxes(); $numberplanlist = $LMS->GetNumberPlans(DOC_CNOTE);
$action = isset($_GET['action']) ? $_GET['action'] : NULL;
$table_id = $DB->GetAll('select id from documents where id in (select docid from invoicecontents where tariffid in (select id from tariffs where taxid=4 and id<>93))and cdate <= unix_timestamp ('2013-12-31 24:00:00.0') and cdate >= unix_timestamp ('2013-01-01 00:00:00.1');');
print(count($table_id)); print("<BR>\n"); flush();
foreach($table_id as $idx => $my_item) { $invoice = $LMS->GetInvoiceContent($my_item['id']); print(".<BR>\n"); flush();
unset($cnote); unset($invoiceid); unset($invoicecontents); unset($nitem);
foreach ($invoice['content'] as $item) { $nitem['tariffid'] = $item['tariffid']; $nitem['name'] = $item['description']; $nitem['prodid'] = $item['prodid']; $nitem['count'] = str_replace(',','.',$item['count']); $nitem['discount'] = str_replace(',','.',$item['discount']); $nitem['jm'] = str_replace(',','.',$item['content']); $nitem['valuenetto'] = str_replace(',','.',$item['basevalue']); $nitem['valuebrutto'] = str_replace(',','.',$item['value']); $nitem['s_valuenetto'] = str_replace(',','.',$item['totalbase']); $nitem['s_valuebrutto'] = str_replace(',','.',$item['total']); $nitem['tax'] = isset($taxeslist[$item['taxid']]) ? $taxeslist[$item['taxid']]['label'] : 0; $nitem['taxid'] = $item['taxid']; $nitem['itemid'] = $item['itemid']; $invoicecontents[$nitem['itemid']] = $nitem; }
$cnote['reason'] = ''; $cnote['paytype'] = $invoice['paytype']; $cnote['cdate'] = 1388505369; $cnote['numberplanid'] = 14;
$t = $invoice['cdate'] + $invoice['paytime']*86400; $deadline = mktime(23, 59, 59, date('m',$t), date('d',$t), date('Y',$t)); if($cnote['cdate'] > $deadline) $cnote['paytime'] = 0; else $cnote['paytime'] = floor(($deadline - $cnote['cdate'])/86400);
$cnote['use_current_division'] = true;
$SESSION->save('cnote', $cnote); $SESSION->save('invoice', $invoice); $SESSION->save('invoiceid', $invoice['id']); $SESSION->save('invoicecontents', $invoicecontents);
$SESSION->restore('invoicecontents', $contents); $SESSION->restore('invoice', $invoice); $SESSION->restore('cnote', $cnote); $SESSION->restore('cnoteerror', $error);
$ntempl = docnumber($invoice['number'], $invoice['template'], $invoice['cdate']); $layout['pagetitle'] = trans('Credit Note for Invoice: $0', $ntempl);
if($cnote['paytime'] < 0) $cnote['paytime'] = 14;
if(!isset($cnote['paytype']) || $cnote['paytype'] == '') $cnote['paytype'] = trans('TRANSFER');
if($contents && $cnote) { $DB->BeginTrans();
$SESSION->restore('invoiceid', $invoice['id']); $newcontents = r_trim($_POST);
foreach($contents as $item) { $idx = $item['itemid']; $contents[$idx]['taxid'] = isset($newcontents['taxid'][$idx]) ? $newcontents['taxid'][$idx] : $item['taxid']; $contents[$idx]['prodid'] = isset($newcontents['prodid'][$idx]) ? $newcontents['prodid'][$idx] : $item['prodid']; $contents[$idx]['jm'] = isset($newcontents['jm'][$idx]) ? $newcontents['jm'][$idx] : $item['jm']; $contents[$idx]['count'] = isset($newcontents['count'][$idx]) ? $newcontents['count'][$idx] : $item['count']; $contents[$idx]['discount'] = isset($newcontents['discount'][$idx]) ? $newcontents['discount'][$idx] : $item['discount']; $contents[$idx]['name'] = isset($newcontents['name'][$idx]) ? $newcontents['name'][$idx] : $item['name']; $contents[$idx]['tariffid'] = isset($newcontents['tariffid'][$idx]) ? $newcontents['tariffid'][$idx] : $item['tariffid']; $contents[$idx]['valuebrutto'] = $newcontents['valuebrutto'][$idx]!='' ? $newcontents['valuebrutto'][$idx] : $item['valuebrutto']; $contents[$idx]['valuenetto'] = $newcontents['valuenetto'][$idx]!='' ? $newcontents['valuenetto'][$idx] : $item['valuenetto']; $contents[$idx]['valuebrutto'] = f_round($contents[$idx]['valuebrutto']); $contents[$idx]['valuenetto'] = f_round($contents[$idx]['valuenetto']); $contents[$idx]['count'] = f_round($contents[$idx]['count']); $contents[$idx]['discount'] = f_round($contents[$idx]['discount']);
$taxvalue = $taxeslist[$contents[$idx]['taxid']]['value'];
if($contents[$idx]['valuenetto'] != $item['valuenetto']) { $contents[$idx]['valuebrutto'] = round($contents[$idx]['valuenetto'] * ($taxvalue / 100 + 1),2); }
if(isset($item['deleted']) && $item['deleted']) { $contents[$idx]['valuebrutto'] = 0; $contents[$idx]['cash'] = round($item['valuebrutto'] * $item['count'],2); $contents[$idx]['count'] = 0; } elseif($contents[$idx]['count'] != $item['count'] || $contents[$idx]['valuebrutto'] != $item['valuebrutto']) { $contents[$idx]['cash'] = round($item['valuebrutto'] * $item['count'],2) - round($contents[$idx]['valuebrutto'] * $contents[$idx]['count'],2); }
$contents[$idx]['valuebrutto'] = $contents[$idx]['valuebrutto'] - $item['valuebrutto']; $contents[$idx]['count'] = $contents[$idx]['count'] - $item['count']; }
$cnote['cdate'] = 1388505369; $cnote['numberplanid'] = 14;
$DB->LockTables(array('documents', 'numberplans'));
if(!isset($cnote['number']) || !$cnote['number']) $cnote['number'] = $LMS->GetNewDocumentNumber(DOC_CNOTE, $cnote['numberplanid'], $cnote['cdate']); else { if(!preg_match('/^[0-9]+$/', $cnote['number'])) $error['number'] = trans('Credit note number must be integer!'); elseif($LMS->DocumentExists($cnote['number'], DOC_CNOTE, $cnote['numberplanid'], $cnote['cdate'])) $error['number'] = trans('Credit note number $0 already exists!', $cnote['number']);
if($error) $cnote['number'] = $LMS->GetNewDocumentNumber(DOC_CNOTE, $cnote['numberplanid'], $cnote['cdate']); }
$DB->Execute('INSERT INTO documents (number, numberplanid, type, cdate, paytime, paytype, userid, customerid, name, address, ten, ssn, zip, city, countryid, reference, reason, divisionid) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($cnote['number'], $cnote['numberplanid'] ? $cnote['numberplanid'] : 0, DOC_CNOTE, $cnote['cdate'], $cnote['paytime'], $cnote['paytype'], $AUTH->id, $invoice['customerid'], $invoice['name'], $invoice['address'], $invoice['ten'], $invoice['ssn'], $invoice['zip'], $invoice['city'], $invoice['countryid'], $invoice['id'], $cnote['reason'], !empty($cnote['use_current_division']) ? $invoice['current_divisionid'] : $invoice['divisionid'], ));
$id = $DB->GetOne('SELECT id FROM documents WHERE number = ? AND cdate = ? AND type = ?', array($cnote['number'],$cnote['cdate'],DOC_CNOTE));
$DB->UnLockTables();
foreach($contents as $idx => $item) { $item['valuebrutto'] = str_replace(',','.', $item['valuebrutto']); $item['count'] = str_replace(',','.', $item['count']); $item['discount'] = str_replace(',','.', $item['discount']);
if ($item['taxid']==4) $item['taxid']=6;
$DB->Execute('INSERT INTO invoicecontents (docid, itemid, value, taxid, prodid, content, count, discount, description, tariffid) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array($id, $idx, $item['valuebrutto'], $item['taxid'], $item['prodid'], $item['jm'], $item['count'], $item['discount'], $item['name'], $item['tariffid'] ));
if(isset($item['cash']) && $item['cash'] != 0) $DB->Execute('INSERT INTO cash (time, userid, value, taxid, customerid, comment, docid, itemid) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', array($cnote['cdate'], $AUTH->id, str_replace(',','.',$item['cash']), $item['taxid'], $invoice['customerid'], $item['name'], $id, $idx )); }
$DB->CommitTrans();
$SESSION->remove('invoice'); $SESSION->remove('invoiceid'); $SESSION->remove('cnote'); $SESSION->remove('invoicecontents'); $SESSION->remove('cnoteerror');
// $SESSION->redirect('?m=invoicelist');
} unset($invoice); }
$SESSION->save('invoice', $invoice); $SESSION->save('cnote', $cnote); $SESSION->save('invoicecontents', $contents); $SESSION->save('cnoteerror', $error);
$SMARTY->assign('error', $error); $SMARTY->assign('contents', $contents); $SMARTY->assign('cnote', $cnote); $SMARTY->assign('invoice', $invoice); $SMARTY->assign('taxeslist', $taxeslist); $SMARTY->assign('numberplanlist', $numberplanlist); $SMARTY->display('invoicenote.html');
?>