noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
compta_ven.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief file included to manage all the operations for the ledger of sales
24 */
25if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
27$gDossier=dossier::id();
28$cn=Dossier::connect();
29//menu = show a list of ledger
30$str_dossier=dossier::get();
33$strac=$http->request('ac');
34$ac="ac=".$strac;
36//@var $post_jrn (int) Ledger id JRN_DEF.JRN_DEF_ID
37$post_jrn=$http->post("p_jrn", "number","");
38//----------------------------------------------------------------------
39// Encode a new invoice
40// empty form for encoding
41//----------------------------------------------------------------------
42
44
45// Check privilege
46if ( isset($_REQUEST['p_jrn']) &&
47 $g_user->check_jrn($http->request("p_jrn","number")) != 'W' )
48{
49
50 NoAccess();
51 exit -1;
52}
53//------------------------------------------------
54/* if a new invoice is encoded, we display a form for confirmation */
55//------------------------------------------------
56if ( isset ($_POST['view_invoice'] ) )
57{
58 $p_jrn=$http->post("p_jrn","number");
60 try
61 {
62 $Ledger->verify_operation($_POST);
63 }
64 catch (Exception $e)
65 {
66 alert($e->getMessage());
67 $p_msg=$e->getMessage();
68 $correct=1;
69 }
70 //------------------------------------------------
71 // Confirm before saving
72 //------------------------------------------------
73 // if correct is not set it means it is correct
74 if ( ! isset($correct))
75 {
76 echo '<div class="content">';
77
78 echo '<div id="confirm_div_id" style="width: 47%; float: left;">';
79 echo h1(_("Confirmation"));
80 echo span(_("Vous devez encore confirmer"),' class="notice"');
81 echo '</div>';
82
83 echo '<div id="confirm_div_id" style="width: 100%; float: left;">';
84 echo '<form class="print" enctype="multipart/form-data" method="post">';
85 echo dossier::hidden();
86 echo $Ledger->confirm($_POST );
87 //----------------------------------------------------
88 // Check that INVOICE can be generated
89 // for e-invoice only
90 //----------------------------------------------------
91 if ($g_parameter->MY_INVOICE_FORMAT != 'BASIC')
92 {
94 $array=[];
95 $array['supplier']=$xmldocument->fill_supplier();
96 $customer=Fiche::from_qcode($cn,trim($http->post("e_client")));
97
98 $array['customer']=$xmldocument->fill_customer($customer->id);
99 $array['operation']=$xmldocument->fill_operation_from_array($_POST);
100 $array['due_date']=$http->post("e_ech");
101 if ( $array['due_date'] == '')
102 {
103 $array['due_date']=$http->post("e_date");
104 }
105 $xmldocument->set_data($array);
106 $xmldocument->display_error();
107 }
108
109 echo HtmlInput::hidden('ac',$strac);
110 $Ledger->input_extra_info();
111 echo '<div class="bt-center">';
112 echo '<ul class="aligned-block">';
113 echo '<li>';
114 echo HtmlInput::submit("record", _("Confirmer"), 'onClick="return verify_ca(\'\');"',p_class:"button");
115 echo '</li>';
116 echo '<li>';
117 echo HtmlInput::submit('correct', _("Corriger"),p_class:"button");
118 echo '</li>';
119 echo '</div>';
120 echo '</form>';
121 echo '</div>';
122 if (DEBUGNOALYSS>1) { echo "<!-- confirm_div_id -->";}
123 return;
124 }
125}
126
127//------------------------------
128/* Record the invoice */
129//------------------------------
130if ( isset($_POST['record']) )
131{
132// Check privilege
133 if ( $g_user->check_jrn($post_jrn) != 'W' )
134 {
135
136 NoAccess();
137 exit -1;
138 }
139
141 try
142 {
143 $Ledger->verify_operation($_POST);
144 }
145 catch (Exception $e)
146 {
147 alert($e->getMessage());
148 $correct=1;
149 }
150
151 if ( ! isset($correct))
152 {
153 if ( is_msie() == 0 )
154 echo '<div style="position:absolute" class="content">';
155 else
156 echo '<div class="content">';
157
159 try {
160 $internal=$Ledger->insert($_POST);
161 $Ledger->upload_supplemental_document($Ledger->jr_id);
162 // var $receipt (string) contains the name of the file name of
163 // the invoice (document created), if empty there
164 // is no invoice
165
166 $receipt='';
167 //-------------------------------------------------------
168 // Generate a XLM invoice
169 // if a document has been created create the XML file
170 //-------------------------------------------------------
171 ///@var $flag_invoice (int) error for invoice generating.
172 /// 0 = nothing no invoice created
173 /// 1 = cannot create e-invoice
174 /// 2 = create e-invoice requested
175
176 $flag_invoice=0;
177 /* Save the attachment or generate doc */
178 if (isset($_FILES['pj']) && noalyss_strlentrim($_FILES['pj']['name']) != 0)
179 {
180 $acc_document=new Acc_Document($cn,$Ledger->jr_id);
181 $acc_document->save_receipt();
183 ,h($_FILES['pj']['name']));
184 }
185 else
186 /* Generate an invoice and save it into the database */
187 if (isset($_POST['gen_invoice']))
188 {
189 // generate an invoice
190 $file = $Ledger->create_document($internal, $_POST);
192 ,h($file));
193 $acc_document=new Acc_Document($cn,$Ledger->jr_id);
194
195 if ($g_parameter->MY_INVOICE_FORMAT != 'BASIC' && ! empty($acc_document->d_filename ))
196 {
197 $flag_invoice=2;
199 $xmldocument->build_data($Ledger->jr_id);
200 $code_error = $xmldocument->verify() ;
201 // check that all the sub arrays are empty
202 if ( ! empty( array_filter($code_error,function($a){ if (!empty($a)) return true; })))
203 {
204 $flag_invoice=1;
205 }
206 }
207 //------------------------------------------------
208 // flag_invoice == 2 , generate an e-invoice
209 //------------------------------------------------
210 if ( $flag_invoice == 2 )
211 {
212 $pdf_filename=$acc_document->d_filename;
213 if ( $acc_document->d_mimetype != 'application/pdf')
214 {
215 $pdf_filename=$acc_document->transform2pdf();
216
217 // save PDF In db
218 $acc_document->update($pdf_filename);
219 }else{
220 $pdf_filename=$_ENV['TMP']."/".$pdf_filename;
221 $acc_document->export_file($pdf_filename);
222 }
223 // make the PDF
224 $xmldocument->set_pdf_filename($pdf_filename);
225
226 // make the XML + PDF
227 //@var $xml(XML String)
228 $xml=$xmldocument->create_invoice($Ledger->jr_id);
229 if (DEBUGNOALYSS > 1) {
230 $mt=date ('ymd-Hi').'+'.$Ledger->jr_id;
231 $uniq= $_ENV['TMP']. DIRECTORY_SEPARATOR."$mt-e-invoice.xml";
232 file_put_contents($uniq, $xml);
233 chmod ($uniq,"0774");
234 echo \Noalyss\Dbg::echo_file("file save $uniq");
235
236 }
237 // FOR BELGIUM : XML and PDF will be stored separately
238 // save XML string into the DB
239 $oid=$cn->lo_write($xml);
240 echo \Noalyss\Dbg::echo_var(1, "oid is $oid");
241 if ($oid == false) {
242 throw new Exception ('CV177 : cannot import e-invoice');
243 }
244 if ( $g_parameter->MY_INVOICE_FORMAT == 'UBL21BEL')
245 {
246 $acc_document->update_document_xml($oid);
247 $receipt= HtmlInput::show_receipt_document($Ledger->jr_id,$acc_document->d_filename)
248 . $acc_document->link_download_xml();
249 }elseif ($g_parameter->MY_INVOICE_FORMAT=='FACTURXFR')
250 {
251 $acc_document->replace_receipt($oid);
252 $receipt= HtmlInput::show_receipt_document($Ledger->jr_id,$acc_document->d_filename);
253 }
254
255 }
256
257 }
258
259
260 }
261 catch (\Exception $e) {
262 if ( $e->getCode()==EXC_BALANCE)
263 echo_warning(_("enregistrement annulé: balance , voyer le fichier log"));
264 else
265 echo_warning($e->getMessage());
266 return;
267 }
268
269
270 /* Save the predefined operation */
271 if ( isset($_POST['opd_name']) && trim($_POST['opd_name']) != "" )
272 {
273 $opd=new Pre_operation($cn);
274 $opd->get_post();
275 $opd->save();
276 }
277
278 /* Show button */
279 echo '<h1>'._("Enregistré").'</h1>';
280 if ($flag_invoice == 1) {
281 echo_warning(_("Impossible de générer facture électronique") );
282 $xmldocument->display_error();
283 }
284 echo $Ledger->confirm($_POST,true);
285 /* Show link for Invoice */
286 if ($receipt != "")
287 {
288 echo '<h2 class="h-section">'._('Document').' </h2>';
289 echo $receipt;
290 }
291
292
293 /* Save the additional information into jrn_info */
295 $obj->save_extra($Ledger->jr_id,$_POST);
296
297 /* save followup */
298 $Ledger->save_followup($http->request("action_gestion","string",""));
299
300 // extourne
301 if (isset($_POST['reverse_ck']))
302 {
303 $p_date=$http->post('reverse_date', "string",'');
304 $p_msg=$http->post("ext_label");
305 if (isDate($p_date)==$p_date)
306 {
307 // reverse the operation
308 try
309 {
310 $Ledger->reverse($p_date,$p_msg);
311 echo '<p>';
312 echo _('Extourné au ').$p_date;
313 echo '</p>';
314
315 }
316 catch (Exception $e)
317 {
318 echo '<span class="warning">'._('Opération non extournée').
319 $e->getMessage().
320 '</span>';
321 }
322 }
323 else
324 {
325 // warning because date is invalid
326 echo '<span class="warning">'._('Date invalide, opération non extournée').'</span>';
327 }
328 }
329 echo '<div class="bt-center">';
330 echo '<ul class="aligned-block">';
331 echo "<li>";
332 echo $Ledger->button_new_operation();
333 echo "</li>";
334 echo "<li>";
335 echo $Ledger->button_copy_operation();
336 echo "</li>";
337 echo "</ul>";
338 echo '</div>';
339 echo '</div>';
340 return;
341 }
342}
343// ------------------------------
344/* Display a blank form or a form with predef operation */
345// ------------------------------
346
347$array=(isset($_POST['correct'])||isset ($correct))?$_POST:null;
349//
350// pre defined operation
351//
352echo '<div class="content">';
353
354if (!isset($_REQUEST ['p_jrn']))
355{
356 $def_ledger=$Ledger->get_first('ven', 2);
357 if (empty($def_ledger))
358 {
359 exit(_('Pas de journal disponible'));
360 }
361 $Ledger->id=$def_ledger['jrn_def_id'];
362}
363else if ( isset($_REQUEST ['p_jrn']) ) {
364 $Ledger->id=$http->request('p_jrn','number');
365}
366else if (isset($_REQUEST['p_jrn_predef']))
367{
368 $Ledger->id=$http->request('p_jrn_predef','number');
369}
370
371
372
373echo '<div class="content">';
374if ($p_msg!="")
375{
376 echo '<span class="warning">'.$p_msg.'</span>';
377}
378try
379{
380 $payment=$http->request("e_mp","string", 0);
381 $date_payment=$http->request("mp_date", "string","");
382 $comm_payment=$http->request("e_comm_paiement", "string","");
383 $acompte=$http->request("acompte", "string",0);
384
385 echo "<FORM class=\"print\" NAME=\"form_detail\" METHOD=\"POST\" >";
386 /* request for a predefined operation */
387 if (isset($_REQUEST['pre_def'])&&!isset($_POST['correct']) && ! isset($correct))
388 {
389 // used a predefined operation
390 //
391 $op=new Pre_operation($cn);
392 $op->set_od_id($http->request('pre_def'));
393 $p_post=$op->compute_array();
394 $Ledger->id=$http->request('p_jrn_predef');
395
396 echo $Ledger->input($p_post);
397 echo '<div class="content">';
398 echo $Ledger->input_paid($payment);
399 echo '</div>';
400 echo '<script>';
401 echo 'compute_all_ledger();';
402 echo '</script>';
403 }
404 else if (isset($_GET['create_invoice']))
405 {
406 $action_id=$http->get('ag_id',"number");
407 $cp=$http->get('cp','number',0);
408 $array=$Ledger->convert_from_follow($action_id,$cp);
409 echo HtmlInput::hidden("ledger_type", "VEN");
410 echo HtmlInput::hidden("ac", $http->get('ac'));
411 echo HtmlInput::hidden("sa", "p");
412 echo HtmlInput::hidden("action_gestion",$action_id);
413 echo $Ledger->input($array);
414 echo '<div class="content">';
415 echo $Ledger->input_paid($payment,$acompte,$date_payment,$comm_payment);
416 echo '</div>';
417 echo '<script>';
418 echo 'compute_all_ledger();';
419 echo '</script>';
420 }
421 else
422 {
423 echo HtmlInput::hidden("ledger_type", "VEN");
424 echo HtmlInput::hidden("ac", $strac);
425 echo HtmlInput::hidden("sa", "p");
426 $action_id=$http->get('ag_id',"string","");
427 echo HtmlInput::hidden("action_gestion",$action_id);
428 echo $Ledger->input($array);
429 echo '<div class="content">';
430 echo $Ledger->input_paid($payment,$acompte,$date_payment,$comm_payment);
431 echo '</div>';
432 echo '<script>';
433 echo 'compute_all_ledger();';
434 echo '</script>';
435 }
436}
437catch (Exception $e)
438{
439 alert($e->getMessage());
440 return;
441}
442echo '<div class="content">';
443
444echo '<div class="bt-center">';
445echo '<ul class="aligned-block">';
446echo '<li>';
447echo HtmlInput::button('act', _('Actualiser'), 'onClick="compute_all_ledger();"', p_class: "button");
448echo '</li>';
449echo '<li>';
450echo HtmlInput::submit("view_invoice", _("Enregistrer"), p_class: "button");
451echo '</li>';
452echo '<li>';
453echo HtmlInput::reset(_('Effacer '), p_class: "button");
454echo '</li>';
455echo '</ul>';
456echo '</div>';
457
458echo '</div>';
459echo "</FORM>";
460
461/* if we suggest the pj n# the run the script */
462 if ( $g_parameter->MY_PJ_SUGGEST=='Y')
463 {
464 echo '<script> update_receipt()</script>';
465 }
466$e_date=$http->request("e_date","string","");
467
468if ($e_date=="" && $g_parameter->MY_DATE_SUGGEST=='Y')
469{
470 echo create_script(" get_last_date()");
471}
472
473
474echo create_script(" update_name()");
475return;
476?>
span($p_string, $p_extra='')
Definition ac_common.php:43
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
noalyss_strlentrim($p_string)
echo_warning($p_string)
warns
h1($p_string, $p_class="")
Definition ac_common.php:72
NoAccess($js=1)
Echo no access and stop.
alert($p_msg, $buffer=false)
alert in javascript
is_msie()
Check if we use IE 8 or 9.
global $g_parameter
global $g_user
if no group available , then stop
switch($op2) $xml
catch(Exception $e) $obj
$op
h( $row[ 'oa_description'])
foreach(array( 'l', 'gDossier') as $a) if(is_numeric($l)==false) $Ledger
$_REQUEST['ac']
if(isset( $_REQUEST[ 'show'])) if(isset($_REQUEST['del'])) $ac
$str_dossier
_("actif, passif,charge,...")
$_GET['qcode']
Document used in accountancy : invoice , credit note, ... It is a specialization of Document used in ...
Manage the additionnal info for operation (from jrn), when an invoice is generated,...
: input, confirm and save new operations in edger of sales the $_POST data is an array with these key...
static from_qcode(Database $cn, string $p_qcode)
create a card from a qcode and returns a card
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static show_receipt_document($p_jr_id, $p_name="")
Returns HTML code for displaying a icon with a link to a receipt document from the ledger.
static reset($p_value, $p_class="smallbutton")
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
static echo_file($msg, $print=true)
display the file
Definition dbg.php:88
static build_xmlinvoice(\Database $conx)
thanks MY_INVOICE_FORMAT , create the corresponding object
manage the predefined operation, link to the table op_def and op_def_detail
if($request_jrn !="" && $g_user->check_jrn($request_jrn) !='W' $p_msg)
$post_jrn
$comm_payment
$date_payment
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
const EXC_BALANCE
Definition constant.php:362
$_POST['ac']
Definition do.php:323
for($e=0; $e< count($afiche); $e++) exit
create_script($p_string)
create the HTML for adding the script tags around of the script
if( $delta< 0) elseif( $delta==0)