noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Acc_Ledger_Purchase Class Reference

Handle the ledger of purchase,. More...

+ Inheritance diagram for Acc_Ledger_Purchase:
+ Collaboration diagram for Acc_Ledger_Purchase:

Public Member Functions

 __construct ($p_cn, $p_init)
 construct
 
 confirm ($p_array, $p_summary=false)
 show the summary of the operation and propose to save it
 
 input ($p_array=null, $p_readonly=0)
 display the form for entering data for invoice
 
 insert ($p_array=null)
 insert into the database, it calls first the verify function change the value of this->jr_id and this->jr_internal. It generates the document and save the middle of payment, if 'gen_invoice is set and e_mp
 
 verify_operation ($p_array)
 verify that the data are correct before inserting or confirming
 
- Public Member Functions inherited from Acc_Ledger
 add_card ($p_filter, $p_id_update)
 Return a button to create new card, depending of the ledger.
 
 button_copy_operation ()
 Show a button to create an operation identical to the recorded one.
 
 button_new_operation ()
 Create a button to encode a new operation into the same ledger.
 
 check_currency ($p_qcode_payment, $p_currency_id)
 When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo reliable , all the bank operation must be in the same currency Operation = Currency 1 and Bank = Currency 2 then it must failed , except if currency 2 (of the bank is the default currency.
 
 check_currency_setting ($p_currency_code)
 Check that the currency code does exist and the setting of the folder is correct.
 
 check_payment ($e_mp, $e_mp_qcode)
 check if the payment method is valid
 
 check_periode ()
 Check if a Dossier is using the check on the periode, if true than the user has to enter the date and the periode, it is a security check.
 
 check_strict ()
 Check if a Dossier is using the strict mode or not.
 
 compute_internal_code ($p_grpt)
 compute the internal code of the saved operation and set the $this->jr_internal to the computed value
 
 convert_from_follow ($p_ag_id, $copy_description=0)
 convert operations from FOLLOWUP into a SALE , FEENOTE or PURCHASE operation into a suitable array
 
 create_document ($internal, $p_array)
 create the invoice and saved it as attachment to the operation,
 
 CurrencyInput ($p_currency_code, $p_currency_rate, $p_eur_amount)
 Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amount.
 
 delete ()
 let you delete a operation
 
 delete_ledger ()
 delete a ledger IF it doesn't contain anything
 
 display_additional_tax ($p_additional_tax, $p_amount)
 in confirm screen , display the compute value for additional tax @parameter $p_additional_tax acc_other_tax.ac_id
 
 display_ledger ()
 display detail of a ledger
 
 display_negative_warning ($p_amount)
 If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
 
 display_warning ($pa_msg, $p_warning)
 Display warning contained in an array.
 
 existing_vat ()
 return the used VAT code with a rate > 0
 
 get_all_fiche_def ()
 retrieve all the card for this type of ledger, make them into a string separated by comma
 
 get_class_def ()
 retrieve the jrn_def_class_deb and return it
 
 get_currency ()
 returns the code iso of the default currency for this ledger
 
 get_customer_late ()
 get info from customer not yet paid
 
 get_customer_now ()
 get info from customer to pay today
 
 get_default_card ($p_ledger_type, $p_side)
 Return an array of default card for the ledger type given.
 
 get_fiche_def ()
 retrieve the jrn_def_fiche and return them into a array index deb, cred
 
 get_first ($p_type, $p_access=3)
 get the first ledger
 
 get_id ($p_internal)
 retrieve the jr_id thanks the internal code, do not change anything to the current object
 
 get_is_loaded ()
 
 get_last ($p_limit)
 return the last p_limit operation into an array
 
 get_last_date ()
 get the date of the last operation
 
 get_last_pj ()
 returns the sequence number of the receipt for the current ledger or create the sequence if it doesn't exist
 
 get_ledger_id ()
 Set the jrn_def.jrn_def_id.
 
 get_min_row ()
 
 get_name ()
 Return the name of a ledger.
 
 get_operation ($p_from, $p_to)
 retrieve operation from jrn
 
 get_operation_date ($p_date, $p_ledger_type, $sql_op)
 Get operation from the ledger type before, after or with the given date .
 
 get_other_amount ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 get_propertie ()
 Get the properties of a journal.
 
 get_rowSimple ($p_from, $p_to, $pa_ledger=[], $trunc=0, $p_limit=-1, $p_offset=-1)
 Get simplified row from ledger Call Acc_Ledger_History_Generic:get_rowSimple.
 
 get_solde ($p_from, $p_to)
 get the saldo of a ledger for a specific period
 
 get_supplier_late ()
 get info from supplier not yet paid
 
 get_supplier_now ()
 get info from supplier to pay today
 
 get_tiers ($p_jrn_type, $jr_id)
 Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
 
 get_tiers_id ($p_jrn_type, $jr_id)
 Return the f_id of the tiers , called by get_tiers.
 
 get_type ()
 Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
 
 guess_pj ()
 guess what the next pj should be
 
 has_other_tax ()
 returns true if the ledger has an additional tax
 
 has_quantity ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 inc_seq_pj ()
 increment the sequence for the pj
 
 input_additional_tax ()
 form : display additional tax available for this ledger and value, set 2 values : checkbox if tax applies and value
 
 input_extra_info ()
 
 input_new ()
 display FORM to enter parameters to create a new ledger.
 
 input_paid ($p_selected, $p_amount=0, $p_date="", $p_comm="")
 Create the section payment.
 
 is_closed ($p_periode)
 check if the current ledger is closed
 
 is_enable ()
 Check if a ledger is enabled , 1 for yes and 0 if disabled.
 
 listing ()
 listing of all ledgers
 
 previous_amount ($p_to)
 retrieve amount of previous periode
 
 previous_other_tax ($p_to)
 retrieve the previous amount
 
 reverse ($p_date, $p_label)
 reverse the operation by creating the opposite one, the result is to avoid it it must be done in
 
 save ($p_array=null)
 save the operation into the jrnx,jrn, , CA and pre_def
 
 save_followup ($s_related_action)
 attach action-followups to an operation,
 
 save_new ($array)
 Insert a new ledger , member variable like jrn_def_id will changed.
 
 search_group ($p_what, $p_value)
 retreive the jr_grpt_id from a ledger
 
 select_default_currency ()
 create a select button to set the default currency for a ledger used only for empty financial ledger
 
 select_depot ($p_readonly, $p_repo)
 Let you select the repository before confirming a sale or a purchase.
 
 select_ledger ($p_type="ALL", $p_access=3, $enable=TRUE)
 Show a select list of the ledgers you can access in writing, reading or simply accessing.
 
 set_currency_id ()
 retrieve currency_id from database
 
 set_is_loaded ($is_loaded)
 
 set_ledger_id ($p_id)
 Set the jrn_def.jrn_def_id.
 
 set_quantity ($p_value)
 set quantity for the ledger to 1 or 0,
 
 update ($array=null)
 update a ledger
 
 update_internal_code ($p_internal)
 
 update_paid ($p_array)
 Update the paiment in the list of operation.
 
 use_quant_table ($p_grpt_id, $p_jrn_type)
 Check if the operation is used in the table quant*.
 
 vat_operation ($p_jr_id)
 get the amount of vat for a given jr_grpt_id from the table quant_purchase
 
 verify_ledger ($array)
 Verify before update.
 

Private Member Functions

 compute_no_deductible (Acc_Compute $p_nd_amount, Fiche $p_fiche)
 Compute the ND amount thanks the attribute of the concerned card.
 
 insert_no_deductible (Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
 Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.
 

Private Attributes

 $payment_operation
 

Additional Inherited Members

- Static Public Member Functions inherited from Acc_Ledger
static array_cat ()
 create an array of the existing cat, to be used in a checkbox form
 
static next_number ($p_cn, $p_type)
 retrieve the next number for this type of ledger
 
static test_me ($pCase='')
 this function is intended to test this class
 
- Data Fields inherited from Acc_Ledger
 $currency_id
 !< default number of rows by default 10
 
 $db
 !< jrn_def.jrn_def_id
 
 $id
 
 $ledger_type
 !< row of the ledger
 
 $nb
 !< type of the ledger ACH ODS FIN VEN or GL
 
 $row
 !< database connextion
 
- Protected Member Functions inherited from Acc_Ledger
 find_label ($p_value)
 Retrieve the label of an accounting.
 
 verify_autonumber ($p_array)
 compare given receipt number and suggested one, if different , it means that the user enters a receipt number if e_pj or e_pj_suggest is not set or empty , or if both are equals then will return true, it returns only if they exist and are different
 
 warn_manual_receipt ($p_array)
 warn if the suggested receipt and receipt are different , it means that the user tried to number himself
 
- Protected Attributes inherited from Acc_Ledger
 $is_loaded
 !< is_loaded true the ledger definition is loaded or false, it is not
 

Detailed Description

Handle the ledger of purchase,.

Definition at line 36 of file acc_ledger_purchase.class.php.

Constructor & Destructor Documentation

◆ __construct()

Acc_Ledger_Purchase::__construct ( $p_cn,
$p_id )

construct

Parameters
$p_cndatabase connexion
$p_idjrn.jrn_def_id

Reimplemented from Acc_Ledger.

Definition at line 40 of file acc_ledger_purchase.class.php.

41 {
42 $this->ledger_type='ACH';
43 parent::__construct($p_cn,$p_init);
44 $this->payment_operation=-1;
45 }

Member Function Documentation

◆ compute_no_deductible()

Acc_Ledger_Purchase::compute_no_deductible ( Acc_Compute $p_nd_amount,
Fiche $p_fiche )
private

Compute the ND amount thanks the attribute of the concerned card.

The object $p_nd_amount will changed

Parameters
Acc_Compute$p_nd_amountobject with ND amount
Fiche$p_ficheConcerned Card (purchase items)
type$p_tva_bot0 TVA on one side, 1 TVA on both side

Definition at line 304 of file acc_ledger_purchase.class.php.

305 {
307 {
308 $p_nd_amount->amount_nd_rate = $p_fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
309 $p_nd_amount->compute_nd();
310 }
312 {
313 $p_nd_amount->nd_vat_rate = $p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
314 $p_nd_amount->compute_nd_vat();
315 }
317 {
318 $p_nd_amount->nd_ded_vat_rate = $p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
319 $p_nd_amount->compute_ndded_vat();
320 }
321
322 if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
323 {
324 $p_nd_amount->amount_perso_rate = $p_fiche->strAttribut(ATTR_DEF_DEP_PRIV);
325 $p_nd_amount->compute_perso();
326 }
327
328 }
compute_nd()
Compute the no deductible part of the amount, it reduce also the vat.
strAttribut($p_ad_id, $p_return=1)
empty_attribute($p_attr)
check if an attribute is empty
const ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP
Definition constant.php:236
const ATTR_DEF_DEP_PRIV
Definition constant.php:233
const ATTR_DEF_TVA_NON_DEDUCTIBLE
Definition constant.php:235
const ATTR_DEF_DEPENSE_NON_DEDUCTIBLE
Definition constant.php:234

References ATTR_DEF_DEP_PRIV, ATTR_DEF_DEPENSE_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP, Acc_Compute\compute_nd(), Acc_Compute\compute_nd_vat(), Acc_Compute\compute_ndded_vat(), Acc_Compute\compute_perso(), Fiche\empty_attribute(), and Fiche\strAttribut().

Referenced by insert().

+ Here is the call graph for this function:

◆ confirm()

Acc_Ledger_Purchase::confirm ( $p_array,
$p_summary = false )

show the summary of the operation and propose to save it

Parameters
arraycontains normally $_POST. It proposes also to save the Analytic accountancy
$p_summarytrue to confirm false, show only the result in RO
Returns
string

Payment method

the function extra info allows to

  • add a attachment
  • generate an invoice
  • insert extra info
    Returns
    html string
    update the payment
    Todo
    to remove, obsolete
    Todo
    Deprecated

Retrieve data from the view v_detail_purchase

Note
$g_user connected user
Parameters
$p_fromjrn.jr_tech_per from
$p_endjrn.jr_tech_per to
Returns
handle to database result

compute an array with the heading cells for the details, used for the export in CSV

Returns
array

Reimplemented from Acc_Ledger.

Definition at line 1575 of file acc_ledger_purchase.class.php.

References $acompte, $amount, $anc, $date_limit, $default_currency, $e_date, $fiche, $g_parameter, $g_user, $i, $jr_id, $jrn_type, $op, $other_tax_amount, $p_array, $p_jrn, $r, $span, $str_code, $tot, $tot_amount, $value, _, ATTR_DEF_ACCOUNT, ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_CP, ATTR_DEF_NAME, Acc_Tva\build(), Acc_Ledger\check_periode(), cn, db, Acc_Ledger\display_negative_warning(), Acc_Ledger\get_name(), h, Acc_Ledger\has_other_tax(), hb(), Anc_Plan\hidden(), Icon_Action\infobulle(), nbm(), noalyss_strlentrim(), span(), td(), tr(), UPDRECEIPT, and Acc_Ledger\warn_manual_receipt().

+ Here is the call graph for this function:

◆ input()

Acc_Ledger_Purchase::input ( $p_array = null,
$p_readonly = 0 )

display the form for entering data for invoice

Parameters
$p_arrayis null or you can put the predef operation or the $_POST
array
'sa' => string 'n' (length=1)
'p_action' => string 'ach' (length=3)
'gDossier' => string '28' (length=2)
'e_client' => string 'ASEKURA' (length=7)
'nb_item' => string '9' (length=1)
'p_jrn' => string '3' (length=1)
'period' => string '126' (length=3)
'e_comm' => string 'descriptio' (length=10)
'e_date' => string '01.05.2010' (length=10)
'e_ech' => string '' (length=0)
'jrn_type' => string 'ACH' (length=3)
'e_pj' => string 'ACH37' (length=5)
'e_pj_suggest' => string 'ACH37' (length=5)
'mt' => string '1273759434.5701' (length=15)
'e_mp' => string '0' (length=1)
'e_march0' => string 'DOC' (length=3)
'e_march0_price' => string '2000' (length=4)
'e_march0_tva_id' => string '3' (length=1)
'e_march0_tva_amount' => string '120' (length=3)
'e_quant0' => string '1' (length=1)
'gen_invoice' => string 'on' (length=2)
'gen_doc' => string '7' (length=1)
'bon_comm' => string '' (length=0)
'other_info' => string '' (length=0)
'correct' => string 'Corriger' (length=8)
Returns
HTML string

Reimplemented from Acc_Ledger.

Definition at line 1184 of file acc_ledger_purchase.class.php.

1185 {
1186 global $g_parameter,$g_user;
1187 // load ledger definition
1188 $this->load();
1189 $http=new HttpInput();
1190 if ( $p_array != null ) extract($p_array, EXTR_SKIP);
1191
1192 $flag_tva=$g_parameter->MY_TVA_USE;
1193
1194 /* Add button */
1195 $str_add_button_tiers = "";
1196 $add_card=FALSE;
1197 if ($g_user->check_action(FICADD) == 1) {
1198 $add_card=TRUE;
1199 $str_add_button_tiers = $this->add_card("cred", "e_client");
1200 }
1201 // The first day of the periode
1202 $oPeriode=new Periode($this->db);
1203 list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($g_user->get_periode());
1204 if ( $g_parameter->MY_DATE_SUGGEST=='Y' )
1205 $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
1206 else
1207 $op_date=( ! isset($e_date) ) ?'':$e_date;
1208
1209 $e_ech=(isset($e_ech))?$e_ech:"";
1210 $e_comm=(isset($e_comm))?$e_comm:"";
1211
1212 $r="";
1213 $r.=dossier::hidden();
1214 $f_legend_detail=_("Détail articles achetés");
1215
1216 // Date
1217 //--
1218 $Date=new IDate();
1219 $Date->setReadOnly(false);
1220 $Date->table=1;
1221 $Date->tabindex=1;
1222 $f_date=$Date->input("e_date",$op_date);
1223 // Payment limit
1224 //--
1225 $Echeance=new IDate();
1226 $Echeance->setReadOnly(false);
1227 $Echeance->tabindex=2;
1229 $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
1230 $f_periode="";
1231 if ($this->check_periode() == true)
1232 {
1233 // Periode
1234 //--
1235 $l_user_per=$g_user->get_periode();
1236 $def=(isset($periode))?$periode:$l_user_per;
1237
1238 $period=new IPeriod("period");
1239 $period->user=$g_user;
1240 $period->cn=$this->db;
1241 $period->value=$def;
1242 $period->type=OPEN;
1243 try
1244 {
1245 $l_form_per=$period->input();
1246 }
1247 catch (Exception $e)
1248 {
1249 record_log($e);
1250 if ($e->getCode() == 1 )
1251 {
1252 throw new Exception( _("Aucune période ouverte"));
1253 }
1254 }
1255
1256 $r.="<td>";
1258 $f_periode=td(_("Période comptable")." $label ").td($l_form_per);
1259 }
1260 // Ledger (p_jrn)
1261 //--
1262 /* if we suggest the next pj, then we need a javascript */
1263 $add_js="";
1264 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1265 {
1266 $add_js="update_receipt();";
1267 }
1268 if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1269 {
1270 $add_js.='get_last_date();';
1271 }
1272 $add_js.='update_name();';
1273 $add_js.='update_pay_method();';
1274 $add_js.='update_row("sold_item");';
1275 $add_js.='update_other_tax();';
1276 $add_js.='update_visibility_quantity();';
1277
1278 $wLedger=$this->select_ledger('ACH',2,FALSE);
1279
1280 if ($wLedger == null) throw new Exception(_('Pas de journal disponible'));
1281 $wLedger->javascript="onChange='update_predef(\"ach\",\"f\",\"".$http->request("ac")."\");$add_js'";
1282 $wLedger->table=0;
1283 $f_jrn=$wLedger->input();
1284
1285 // Comment
1286 //--
1287 $Commentaire=new IText();
1288 $Commentaire->table=0;
1289 $Commentaire->setReadOnly(false);
1290 $Commentaire->size=60;
1291 $Commentaire->tabindex=3;
1293 $f_desc=$Commentaire->input("e_comm",$e_comm);
1294
1295 // PJ
1296 //--
1297 /* suggest PJ ? */
1298 $default_pj='';
1299 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1300 {
1301 $default_pj=$this->guess_pj();
1302 }
1303
1304 $pj=new IText();
1305 $pj->value=(isset($e_pj))?$e_pj:$default_pj;
1306
1307 if ( $g_parameter->MY_PJ_SUGGEST=='A' || $g_user->check_action(UPDRECEIPT)==0)
1308 {
1309 $pj->setReadOnly(true);
1310 $pj->id="e_pj";
1311 }
1312 $pj->table=0;
1313 $pj->name="e_pj";
1314 $pj->size=10;
1315 $pj->readonly=false;
1316
1317 $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
1318
1319 // Display the customer
1320 //--
1321 $fiche='cred';
1322
1323 // Save old value and set a new one
1324 //--
1325 $e_client=( isset ($e_client) )?$e_client:"";
1326 $e_client_label="&nbsp;";//str_pad("",100,".");
1327
1328
1329 // retrieve e_client_label
1330 //--
1331
1332 if ( noalyss_strlentrim($e_client) != 0)
1333 {
1334 $fClient=new Fiche($this->db);
1335 $fClient->get_by_qcode($e_client);
1336 $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
1337 ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
1338 $fClient->strAttribut(ATTR_DEF_CP).' '.
1339 $fClient->strAttribut(ATTR_DEF_CITY).' ';
1340
1341
1342 }
1343
1344 $W1=new ICard();
1345 $W1->label=_("Fournisseur ").Icon_Action::infobulle(0) ;
1346 $W1->name="e_client";
1347 $W1->tabindex=3;
1348 $W1->value=$e_client;
1349 $W1->table=0;
1350 $W1->set_dblclick("fill_ipopcard(this);");
1351 $W1->set_attribute('ipopup','ipopcard');
1352
1353 // name of the field to update with the name of the card
1354 $W1->set_attribute('label','e_client_label');
1355 // name of the field to update with the name of the card
1356 $W1->set_attribute('typecard','cred');
1357
1358 // Add the callback function to filter the card on the jrn
1359 $W1->set_callback('filter_card');
1360 $W1->set_function('fill_data');
1361 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1362 $W1->name);
1363 $f_client_qcode=$W1->input();
1364 $client_label=new ISpan();
1365 $client_label->style="vertical-align:top";
1366 $client_label->table=0;
1367 $f_client=$client_label->input("e_client_label",$e_client_label);
1368 $f_client_bt=$W1->search();
1369
1370
1371 // Record the current number of article
1372
1373 $e_comment=(isset($e_comment))?$e_comment:"";
1374 $p_article= ( isset ($nb_item))?$nb_item:$this->get_min_row();
1375 $p_article=($p_article < $this->get_min_row())?$this->get_min_row():$p_article;
1376
1377 $Hid=new IHidden();
1378 $r.=$Hid->input("nb_item",$p_article);
1379
1380 // For each article
1381 //--
1382 for ($i=0;$i< $p_article ;$i++)
1383 {
1384 // Code id, price & vat code
1385 //--
1386 $march=(isset(${"e_march$i"}))?${"e_march$i"}:"" ;
1387 $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
1388 ;
1389 /* use vat */
1390 if ( $g_parameter->MY_TVA_USE=='Y')
1391 {
1392 $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
1393 $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
1394 }
1395
1396
1397
1398 $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
1399 // retrieve the tva label and name
1400 //--
1401 if ( noalyss_strlentrim($march)!=0 && noalyss_strlentrim($march_label)==0 )
1402 {
1403 $fMarch=new Fiche($this->db);
1404 $fMarch->get_by_qcode($march);
1405 $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
1406 /* vat use */
1407 if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
1408 $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
1409 }
1410 // Show input
1411 //--
1412 $W1=new ICard();
1413 $W1->label="";
1414 $W1->name="e_march".$i;
1415 $W1->value=$march;
1416 $W1->table=0;
1417 $W1->set_dblclick("fill_ipopcard(this);");
1418 $W1->set_attribute('ipopup','ipopcard');
1419
1420 $W1->set_attribute('typecard','deb');
1421
1422 // name of the field to update with the name of the card
1423 $W1->set_attribute('label','e_march'.$i.'_label');
1424 // name of the field with the price
1425 $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
1426 $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
1427
1428 // name of the field with the TVA_ID
1429 $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
1430 // Add the callback function to filter the card on the jrn
1431 $W1->set_callback('filter_card');
1432 $W1->set_function('fill_data');
1433 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1434 $W1->name);
1435 $W1->readonly=false;
1436 $array[$i]['quick_code']=$W1->input();
1437 $array[$i]['bt']=$W1->search();
1438 $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("deb", $W1->id):"";
1439
1440 $array[$i]['hidden']='';
1441 // For computing we need some hidden field for holding the value
1442 if ( $g_parameter->MY_TVA_USE=='Y')
1443 {
1444 $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
1445 }
1446
1447 if ( $g_parameter->MY_TVA_USE=='Y')
1448 $tvac=new INum('tvac_march'.$i);
1449 else
1450 $tvac=new IHidden('tvac_march'.$i);
1451
1452 $tvac->readOnly=1;
1453 $tvac->value=0;
1454 $array[$i]['tvac']=$tvac->input();
1455
1456 $htva=new INum('htva_march'.$i);
1457 $htva->readOnly=1;
1458
1459 $htva->value=0;
1460 $array[$i]['htva']=$htva->input();
1461
1462 if ( $g_parameter->MY_UPDLAB == 'Y')
1463 {
1464 $Span=new IText("e_march".$i."_label");
1465 $Span->style='class="input_text label_item"';
1466 } else
1467 {
1468 $Span=new ISpan("e_march".$i."_label");
1469 $Span->extra='class="label_item"';
1470 }
1471 $Span->value=$march_label;
1472 $Span->setReadOnly(false);
1473 // card's name, price
1474 //--
1475 $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
1476 // price
1477 $Price=new INum();
1478 $Price->setReadOnly(false);
1479 $Price->size=9;
1480 $Price->javascript="onblur=\"format_number(this,4);clean_tva($i);compute_ledger($i)\"";
1481 $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
1482 if ( $g_parameter->MY_TVA_USE=='Y')
1483 {
1484
1485 // vat label
1486 //--
1487 $Tva=new ITva_Popup($this->db);
1488 $Tva->js="onblur=\"clean_tva($i);compute_ledger($i)\"";
1489 $Tva->in_table=true;
1490 $Tva->set_attribute('compute',$i);
1491 $Tva->set_filter("purchase");
1492 $Tva->value=$march_tva_id;
1493 $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
1494
1495 // Tva_amount
1496
1497 // price
1498 $Tva_amount=new INum();
1499 $Tva_amount->setReadOnly(false);
1500 $Tva_amount->size=9;
1501 $Tva_amount->javascript="onblur=\"format_number(this);compute_ledger($i)\"";
1502 $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
1503 }
1504 // quantity
1505 //--
1506 $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
1507 ;
1508 $Quantity=new INum();
1509 $Quantity->setReadOnly(false);
1510 $Quantity->size=9;
1511 $Quantity->javascript="onchange=\"format_number(this,2);clean_tva($i);compute_ledger($i)\"";
1512 $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
1513
1514 }
1515 $f_type=_('Fournisseur');
1516
1517 // Currency
1518 $currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
1519 $currency_select->selected=$http->request('p_currency_code','string',0);
1520
1521 $currency_input=new INum("p_currency_rate");
1522 $currency_input->prec=8;
1523 $currency_input->id="p_currency_rate";
1524 $currency_input->value=$http->request('p_currency_rate','string',1);
1525 $currency_input->javascript='onchange="format_number(this,6);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
1526
1527 $currency=new Acc_Currency($this->db,0);
1528
1529 //
1530 // Button for template operation
1531 //
1532 ob_start();
1533 echo '<div id="predef_form">';
1534 echo HtmlInput::hidden('p_jrn_predef', $this->id);
1535 $op = new Pre_operation($this->db);
1536 $op->set_p_jrn($this->id);
1537 $op->set_jrn_type("ACH");
1538 $op->set_od_direct('f');
1539 $url=http_build_query(array('p_jrn_predef'=>$this->id,'ac'=>$http->request('ac'),'gDossier'=>dossier::id()));
1540 echo $op->form_get('do.php?'.$url);
1541 echo '</div>';
1542 $str_op_template=ob_get_contents();
1543 ob_end_clean();
1544
1545 ob_start();
1546 require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1547 $r.=ob_get_contents();
1548 ob_end_clean();
1549
1550 // Set correctly the REQUEST param for jrn_type
1551 $r.= HtmlInput::hidden('jrn_type','ACH');
1553
1554
1555
1556 /* if we suggest the pj n# the run the script */
1557 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1558 {
1559 $r.='<script> update_receipt();</script>';
1560 }
1561 // set focus on date
1562 $r.= create_script("$('".$Date->id."').focus()");
1563 $r.='<div id="additional_tax_div">';
1564 $r.=$this->input_additional_tax();
1565 $r.='</div>';
1566 return $r;
1567 }
noalyss_strlentrim($p_string)
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
_("actif, passif,charge,...")
CurrencyInput($p_currency_code, $p_currency_rate, $p_eur_amount)
Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amou...
select_ledger($p_type="ALL", $p_access=3, $enable=TRUE)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
input_additional_tax()
form : display additional tax available for this ledger and value, set 2 values : checkbox if tax app...
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
$db
!< jrn_def.jrn_def_id
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
guess_pj()
guess what the next pj should be
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
static hidden($p_name, $p_value, $p_id="")
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
$def
show a form for quick_writing
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
const ATTR_DEF_ADRESS
Definition constant.php:223
const OPEN
Definition constant.php:201
const ATTR_DEF_NAME
Definition constant.php:216
const ATTR_DEF_CP
Definition constant.php:224
const ATTR_DEF_TVA
Definition constant.php:221
const ATTR_DEF_CITY
Definition constant.php:229
const FICADD
const UPDRECEIPT
$oPeriode
Definition do.php:156
$SecUser db
create_script($p_string)
create the HTML for adding the script tags around of the script

References $array, $currency, Acc_Ledger\$db, $def, $e, $e_date, $fiche, $g_parameter, $g_user, $http, $i, $label, $op, $oPeriode, $p_array, $p_readonly, $periode, $r, $url, $wLedger, _, Acc_Ledger\add_card(), ATTR_DEF_ADRESS, ATTR_DEF_CITY, ATTR_DEF_CP, ATTR_DEF_NAME, ATTR_DEF_TVA, Acc_Ledger\check_periode(), create_script(), Acc_Ledger\CurrencyInput(), db, FICADD, Acc_Ledger\get_min_row(), Acc_Ledger\guess_pj(), Icon_Action\infobulle(), Acc_Ledger\input_additional_tax(), Html_Input_Noalyss\ledger_add_item(), noalyss_strlentrim(), OPEN, record_log(), Acc_Ledger\select_ledger(), td(), and UPDRECEIPT.

+ Here is the call graph for this function:

◆ insert()

Acc_Ledger_Purchase::insert ( $p_array = null)

insert into the database, it calls first the verify function change the value of this->jr_id and this->jr_internal. It generates the document and save the middle of payment, if 'gen_invoice is set and e_mp

Parameters
$p_arrayis usually $_POST or a predefined operation
Array
(
[e_client] =>BELGACOM
[nb_item] =>9
[p_jrn] =>3
[period] =>117
[e_comm] =>Frais de téléphone
[e_date] =>01.09.2009
[e_ech] =>
[jrn_type] =>ACH
[e_pj] =>ACH53
[e_pj_suggest] =>ACH53
[mt] =>1265318941.39
[e_mp] =>0
[e_march0] =>TEL
[e_march0_price] =>63.6700
[e_march0_tva_id] =>1
[e_march0_tva_amount] =>13.3700
[e_quant0] =>1.000
...
[bon_comm] =>
[other_info] =>
[record] =>Enregistrement
[p_currency_code]=> id currency
[p_currency_rate]=>rate used
)
Returns
string
Note
throw an Exception

= e_pj then do not increment sequence , if the given receipt number is equal to one computed then increment

Definition at line 518 of file acc_ledger_purchase.class.php.

519 {
520 global $g_parameter,$g_user;
521 extract ($p_array, EXTR_SKIP);
522 $this->verify($p_array) ;
523 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
524 $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
525 $seq=$this->db->get_next_seq('s_grpt');
526 $this->id=$p_jrn;
527
528 $internal=$this->compute_internal_code($seq);
529 $this->internal=$internal;
530
531 $cust=new Fiche($this->db);
532 $cust->get_by_qcode($e_client);
533 $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
534 // if 2 accounts, take only the credit Supplier
535 if ( strpos($sposte,',') != 0 )
536 {
537 $array=explode(',',$sposte);
538 $poste=$array[1];
539 }
540 else
541 {
542 $poste=$sposte;
543 }
544
545 $oPeriode=new Periode($this->db);
547
548 if ( $check_periode == true && isset($p_array['period']) )
549 $tperiode=$period;
550 else
551 $tperiode=$oPeriode->find_periode($e_date);
552
553
554 try
555 {
556 bcscale(4);
557 // variable : $tot_amount float : total amount of the purchase (debit)
558 $tot_amount=0;
559
560 // variable : $tot_tva float : total amount of the VAT
561 $tot_tva=0;
562
563 // variable: $tot_debit float : amount on debit side
564 $tot_debit=0;
565
566 $this->db->start();
567
568
569 // variable: $tot_tva_reversed float total VAT autoreverse, to deduce from supplier's amount
570 $tot_tva_reversed=0;
571
572 // variable : $tva array that will contain all the VAT Amount
573 $tva=array();
574
575 // variable : $tva_reverse array that contain all the VAT autoreverse AND negative
576 $tva_reverse = array();
577
578 // variable : $tva_reverse_credit array that contain all the VAT autoreverse for credit
579 $tva_reverse_credit = array();
580
581 // variable : $tot_amount_cur : total amount in currency
582 $tot_amount_cur=0;
583
584 // find the currency from v_currency_last_value
585 // variable : $currency_rate_ref Acc_Currency , currency object for this operation
586 $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
587
588 /* Save all the items without vat and no deductible vat and expense*/
589 for ($i=0;$i< $nb_item;$i++)
590 {
591 if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
592
593 /* First we save all the items without vat */
594 $fiche=new Fiche($this->db);
595 $fiche->get_by_qcode(${"e_march".$i});
596 // variable : $tva_both integer 1 for autoreverse ,0 normal, fetch it once for this item,
597 $tva_both=0;
598 /* tva */
599 if ($g_parameter->MY_TVA_USE=='Y')
600 {
601 $idx_tva=trim(${'e_march'.$i.'_tva_id'});
602 $oTva=Acc_Tva::build($this->db,$idx_tva);
603
604 $oTva->load();
605 $tva_both=$oTva->get_parameter("both_side");
606 }
607 /* -- Create acc_operation -- */
608 $acc_operation=new Acc_Operation($this->db);
609 $acc_operation->date=$e_date;
610 $acc_operation->grpt=$seq;
611 $acc_operation->jrn=$p_jrn;
612 $acc_operation->type='d';
613 $acc_operation->periode=$tperiode;
614 $acc_operation->qcode="";
615 $amount_4=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
616
617 /* We have to compute all the amount thanks Acc_Compute */
618
619 $acc_amount=new Acc_Compute();
620 $acc_amount->check=false;
621 $acc_amount->set_parameter('amount',$amount_4);
622 // Set the currency rate
623 $acc_amount->set_parameter("currency_rate", $p_currency_rate);
624 $acc_amount->convert_euro();
625 $amount_euro=$acc_amount->amount;
626
627 // Compute VAT or take the given one
628 if ( $g_parameter->MY_TVA_USE=='Y')
629 {
630 $acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
631 if ( noalyss_strlentrim(${'e_march'.$i.'_tva_amount'}) ==0 || ${'e_march'.$i.'_tva_amount'} == 0)
632 {
633 // vat must computed and the amount is already converted to EUR
634 $acc_amount->compute_vat();
635
636 }
637 else
638 {
639 // we convert the vat in euro
640 $acc_amount->set_parameter("amount_vat", ${'e_march'.$i.'_tva_amount'});
641 $acc_amount->convert_euro_vat();
642
643 }
644 // convert amount in eur
645 $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
646 $tot_tva=round($tot_tva,2);
647 }
648
649
650 /* compute ND */
651 // variable: $save_amount_vat total float amount of VAT before changing due to NOT DEDUCTIBLE
652 $save_amount_vat=$acc_amount->amount_vat;
653 $this->compute_no_deductible($acc_amount, $fiche);
654 $acc_amount->correct();
655 // TVA which avoid
656 if ( $tva_both == 1 ) {
657 $acc_amount->autoreverse=$save_amount_vat;
658 $tot_tva_reversed=bcadd($tot_tva_reversed,$save_amount_vat);
659 }
660
661
662
663 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount),2);
664 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount_nd),2);
665 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount_perso),2);
666
667 /* get the account and explode if necessary */
668 $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
669 // if 2 accounts, take only the debit one for customer
670 if ( strpos($sposte,',') != 0 )
671 {
672 $array=explode(',',$sposte);
673 $poste_val=$array[0];
674 }
675 else
676 {
677 $poste_val=$sposte;
678 }
679 if ($g_parameter->MY_UPDLAB=='Y')
680 {
681 $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
682 }
683 else
684 {
685 $acc_operation->desc=null;
686 }
687 $acc_operation->poste=$poste_val;
688 $acc_operation->amount=$acc_amount->amount;
689 $acc_operation->qcode=${"e_march".$i};
690 if ($acc_amount->amount>0)
691 {
692 $tot_debit=bcadd($tot_debit, $acc_amount->amount);
693 }
694 $j_id=$acc_operation->insert_jrnx();
695
696 /* insert ND */
697 $this->insert_no_deductible($acc_amount, $fiche, $tva_both, $tot_debit,$acc_operation,$group,$i);
698
699
700 /* Compute sum vat */
701 if ( $g_parameter->MY_TVA_USE=='Y')
702 {
703 $tva_item=$acc_amount->amount_vat;
704
705 if ($tva_both == 0 ){
706 $tva[$idx_tva]=(isset( $tva[$idx_tva]))? $tva[$idx_tva]:0;
707 $tva[$idx_tva]=bcadd($tva[$idx_tva], $tva_item);
708 }else {
709 // $tva_item < 0 && $tva_both == 1
710 $tva_reverse[$idx_tva]=(isset($tva_reverse[$idx_tva]))?$tva_reverse[$idx_tva]:0;
711 $tva_reverse[$idx_tva]=bcadd($tva_item,$tva_reverse[$idx_tva]);
712 $tva_reverse_credit[$idx_tva]=(isset($tva_reverse_credit[$idx_tva]))?$tva_reverse_credit[$idx_tva]:0;
713 $tva_reverse_credit[$idx_tva]=bcadd($save_amount_vat,$tva_reverse_credit[$idx_tva]);
714 }
715 }
716 /* Save the stock */
717 /* if the quantity is < 0 then the stock increase (return of
718 * material)
719 */
720 $nNeg=(${"e_quant" . $i}< 0) ? -1 : 1;
721
722 // always save quantity but in withStock we can find
723 // what card need a stock management
724 if ( $g_parameter->MY_STOCK='Y'&& isset ($repo))
725 {
726 $dir=(${'e_quant'.$i} < 0 ) ? 'c':'d';
727 Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo)) ;
728 }
729
730 if ( $g_parameter->MY_ANALYTIC != "nu" && $g_parameter->match_analytic($poste_val))
731 {
732 // for each item, insert into operation_analytique */
733 $op=new Anc_Operation($this->db);
734 $op->set_currency_rate($p_currency_rate);
735 $op->oa_group=$group;
736 $op->j_id=$j_id;
737 $op->oa_date=$e_date;
738 $op->oa_debit='t';
739 $op->oa_description=sql_string($e_comm);
740 $op->save_form_plan($p_array,$i,$j_id);
741 }
742 // insert into quant_purchase
743 //-----
744
745 if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0;
746 if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0;
747 if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0;
748 $price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
749
750 if ( $g_parameter->MY_TVA_USE=='Y')
751 {
752
753 $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
754 array(
755 null /*1*/
756 ,$j_id /* 2 */
757 ,${"e_march".$i} /* 3 */
758 ,${"e_quant".$i} /* 4 */
759 ,round($amount_euro,2) /* 5 */
760 ,$acc_amount->amount_vat /* 6 */
761 ,$oTva->get_parameter('id') /* 7 */
762 ,$acc_amount->amount_nd /* 8 */
763 ,$acc_amount->nd_vat /* 9 */
764 ,$acc_amount->nd_ded_vat /* 10 */
765 ,$acc_amount->amount_perso /* 11 */
766 ,$e_client /* 12 */
767 , $acc_amount->autoreverse /*13*/
768 ,$price_euro /* 14 */
769 ));
770
771
772 }
773 else
774 {
775 $acc_amount->amount_vat=0;
776 $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
777 array(
778 null /*1*/
779 ,$j_id /* 2 */
780 ,${"e_march".$i} /* 3 */
781 ,${"e_quant".$i} /* 4 */
782 ,round($acc_amount->amount,2) /* 5 */
783 ,0 /* 6 */
784 ,null/* 7 */
785 ,$acc_amount->amount_nd /* 8 */
786 ,0 /* 9 */
787 ,$acc_amount->nd_ded_vat /* 10 */
788 ,$acc_amount->amount_perso /* 11 */
789 ,$e_client /* 12 */
790 , $acc_amount->autoreverse /*13*/
791 ,$price_euro /* 14 */
792 ));
793 }
794 /*
795 * Insert also in operation_currency
796 */
797 $operation_currency=new Operation_currency_SQL($this->db);
798 $operation_currency->oc_amount=$acc_amount->amount_currency;
799 $operation_currency->oc_vat_amount=($tva_both==0)?$acc_amount->amount_vat_currency:0;
800 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
801 $operation_currency->j_id=$j_id;
802 $operation_currency->insert();
803 $tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_currency,4),4);
804 $tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_vat_currency,4),4);
805 if ( DEBUGNOALYSS > 1 ) {
806 echo __LINE__." insert into operation currency oc_amount:{$acc_amount->amount_currency} oc_vat_amount {$acc_amount->amount_vat_currency} <br>";
807 }
808 } // end loop : save all items
809
810
811 /*** save other tax ****/
812 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
813 $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
814 from acc_other_tax
815 where ac_id=$1 ",
816 [$p_array['other_tax']]);
817 if ( ! empty ($row )) {
818 $other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
819 $acc_operation=new Acc_Operation($this->db);
820 $acc_operation->date=$e_date;
821 $acc_operation->poste=$row['ac_accounting'];
822 $acc_operation->amount=$other_tax_amount;
823 $acc_operation->grpt=$seq;
824 $acc_operation->jrn=$p_jrn;
825 $acc_operation->type='d';
826 $acc_operation->periode=$tperiode;
827 $acc_operation->desc=$row['ac_label'];
828 $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
829 $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
830 $jrn_tax_sql->ac_id=$row['ac_id'];
831 $jrn_tax_sql->pcm_val=$row['ac_accounting'];
832 $jrn_tax_sql->insert();
833 $operation_currency=new Operation_currency_SQL($this->db);
834 $operation_currency->oc_amount=$p_array['other_tax_amount'];
835 $operation_currency->oc_vat_amount=0;
836 $operation_currency->oc_price_unit=0;
837 $operation_currency->j_id=$jrn_tax_sql->j_id;
838 $operation_currency->insert();
839
840 $tot_debit=bcadd($tot_debit, abs($other_tax_amount));
842 }
843
844 }
845
846
847 /*** save total customer ***/
848 if ( DEBUGNOALYSS > 1 ) {
849 echo __LINE__." tot_amount $tot_amount<br>";
850 echo __LINE__." tot_tva $tot_tva<br>";
851
852 }
853 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
854 $acc_operation=new Acc_Operation($this->db);
855 $acc_operation->date=$e_date;
856 $acc_operation->poste=$poste;
857 $acc_operation->amount=bcsub($cust_amount,$tot_tva_reversed);
858 $acc_operation->grpt=$seq;
859 $acc_operation->jrn=$p_jrn;
860 $acc_operation->type='c';
861 $acc_operation->periode=$tperiode;
862 $acc_operation->qcode=${"e_client"};
863 if ($cust_amount<0)
864 {
865 $tot_debit=bcadd($tot_debit, abs($cust_amount));
866 }
867 $let_client=$acc_operation->insert_jrnx();
868
869 // --- insert also the currency amount for the customer
870 $operation_currency=new Operation_currency_SQL($this->db);
871 $operation_currency->oc_amount=$tot_amount_cur;
872 $operation_currency->oc_vat_amount=0;
873 $operation_currency->oc_price_unit=0;
874 $operation_currency->j_id=$let_client ;
875 $operation_currency->insert();
876
877 if ( $g_parameter->MY_TVA_USE=='Y')
878 {
879 /* save all vat
880 * $i contains the tva_id and value contains the vat amount
881 */
882 foreach ($tva as $i => $value)
883 {
884 $oTva=Acc_Tva::build($this->db,$i);
885 $poste_vat=$oTva->get_side('d');
886
887 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
888 $acc_operation=new Acc_Operation($this->db);
889 $acc_operation->date=$e_date;
890 $acc_operation->poste=$poste_vat;
891 $acc_operation->amount=$value;
892 $acc_operation->grpt=$seq;
893 $acc_operation->jrn=$p_jrn;
894 $acc_operation->type='d';
895 $acc_operation->periode=$tperiode;
896 if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value));
897 $acc_operation->insert_jrnx();
898
899 } // LOOP : foreach $tva
900 foreach ($tva_reverse as $i => $value) {
901 $oTva = Acc_Tva::build($this->db,$i);
902 $poste_vat = $oTva->get_side('d');
903 if ( $poste_vat == '#')
904 {
905 $poste_vat=$oTva->get_side('c');
906 }
907
908 $acc_operation = new Acc_Operation($this->db);
909 $acc_operation->date = $e_date;
910 $acc_operation->poste = $poste_vat;
911 $acc_operation->amount = $value;
912 $acc_operation->grpt = $seq;
913 $acc_operation->jrn = $p_jrn;
914 $acc_operation->type = 'd';
915 $acc_operation->periode = $tperiode;
916
917 $acc_operation->insert_jrnx();
918
919 // if TVA is on both side, we deduce it immediately
920 // $x temp variable is the tva_reverse_account and will be used to check $poste_vat
921 $x=$oTva->get_parameter("tva_reverse_account");
922 $poste_vat =(trim($x??"")=="")? $oTva->get_side('c'):$x;
923
924 if ( $poste_vat == '#')
925 {
926 $poste_vat=$oTva->get_side('d');
927 }
928 $acc_operation = new Acc_Operation($this->db);
929 $acc_operation->date = $e_date;
930 $acc_operation->poste = $poste_vat;
931 $acc_operation->amount = $tva_reverse_credit[$i];
932 $acc_operation->grpt = $seq;
933 $acc_operation->jrn = $p_jrn;
934 $acc_operation->type = 'c';
935 $acc_operation->periode = $tperiode;
936 $acc_operation->insert_jrnx();
937 $tot_debit = bcadd($tot_debit, $value);
938 $tot_debit = round($tot_debit, 2);
939 } //LOOP: foreach $tva_reverse
940 }
941
942 /* insert into jrn */
943 $acc_operation=new Acc_Operation($this->db);
944 $acc_operation->date=$e_date;
945 $acc_operation->echeance=$e_ech;
946 // Total DEB
947 $acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'",
948 array($seq));
949 $acc_operation->desc=$e_comm;
950 $acc_operation->grpt=$seq;
951 $acc_operation->jrn=$p_jrn;
952 $acc_operation->periode=$tperiode;
953 $acc_operation->pj=$e_pj;
954 $acc_operation->mt=$mt;
955 $acc_operation->currency_id=$p_currency_code;
956 $acc_operation->currency_rate=$p_currency_rate;
957 $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
958
959 if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
960 throw new Exception (_("Erreur de balance"),EXC_BALANCE);
961 }
962 $this->pj=$acc_operation->update_receipt();
963
964 // Set Internal code
965 $this->grpt_id=$seq;
966 $this->update_internal_code($internal);
967 /* update quant_purchase */
968 $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
969 array($internal,$seq));
970
971 /**= e_pj then do not increment sequence , if the given receipt number is equal to one computed then increment */
972 if ($e_pj == $this->pj && noalyss_strlentrim($e_pj) != 0)
973 {
974 $this->inc_seq_pj();
975 }
976
977 /* Save the attachment */
978 if ( isset ($_FILES))
979 {
980 if ( sizeof($_FILES) != 0 )
981 $this->db->save_receipt($seq);
982 }
983 $str_file="";
984 /* Generate an document and save it into the database (Note de frais only)
985 */
986 if ( isset($_POST['gen_invoice']) )
987 {
988 $ref_doc= $this->create_document($internal,$p_array);
989 $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($ref_doc));
990 }
991
992 //----------------------------------------
993 // Save the payer
994 //----------------------------------------
995 if ( $e_mp != 0 )
996 {
997 /* mp */
998 $mp=new Acc_Payment($this->db,$e_mp);
999 $mp->load();
1000
1001 /* jrnx */
1002 $acseq=$this->db->get_next_seq('s_grpt');
1003 $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger_target'));
1004 $acinternal=$acjrn->compute_internal_code($acseq);
1005 /*
1006 * for the use of the card of the bank
1007 */
1008 if ( $acjrn->get_type()=='FIN') {
1009 $acjrn=new Acc_Ledger_Fin($this->db, $mp->get_parameter('ledger_target'));
1010 $acfiche=new Fiche($this->db,$acjrn->get_bank());
1011 $fqcode=$acfiche->strAttribut(ATTR_DEF_QUICKCODE);
1012 } else {
1013 $fqcode = ${'e_mp_qcode_' . $e_mp};
1014 $acfiche = new Fiche($this->db);
1015 $acfiche->get_by_qcode($fqcode);
1016 }
1017 /* Insert paid by */
1018 $acc_pay=new Acc_Operation($this->db);
1019 $acc_pay->date=$e_date;
1020
1021 /* get the account and explode if necessary */
1022 $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
1023 // if 2 accounts, take only the debit one for customer
1024 if ( strpos($sposte,',') != 0 )
1025 {
1026 $array=explode(',',$sposte);
1027 $poste_val=$array[1];
1028 }
1029 else
1030 {
1031 $poste_val=$sposte;
1032 }
1033 // remove the VAT autoliquidation
1034 $cust_amount=bcsub($cust_amount, $tot_tva_reversed);
1035
1036 // Convert paid amount in EUR
1037 $acompte_defcur=bcdiv($acompte, $p_currency_rate);
1038
1039 $famount=bcsub($cust_amount,$acompte_defcur);
1040
1041 $acc_pay->poste=$poste_val;
1042 $acc_pay->qcode=$fqcode;
1043 $acc_pay->amount=abs(round($famount,2));
1044 $acc_pay->desc='';
1045 $acc_pay->grpt=$acseq;
1046 $acc_pay->jrn=$mp->get_parameter('ledger_target');
1047 $acc_pay->periode=$tperiode;
1048 $acc_pay->type=($famount>=0)?'c':'d';
1049 $let_pay=$acc_pay->insert_jrnx();
1050
1051 /* Insert supplier */
1052 $acc_pay=new Acc_Operation($this->db);
1053 $acc_pay->date=empty($mp_date)?$e_date:$mp_date;
1054 $acc_pay->poste=$poste;
1055 $acc_pay->qcode=$e_client;
1056 $acc_pay->amount=abs(round($famount,2));
1057 $acc_pay->desc='';
1058 $acc_pay->grpt=$acseq;
1059 $acc_pay->jrn=$mp->get_parameter('ledger_target');
1060 $acc_pay->periode=$tperiode;
1061 $acc_pay->type=($famount>=0)?'d':'c';
1062 $let_other=$acc_pay->insert_jrnx();
1063
1064 // insert into operation_currency
1065 $operation_currency=new Operation_currency_SQL($this->db);
1066 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
1067 $operation_currency->oc_vat_amount=0;
1068 $operation_currency->oc_price_unit=0;
1069 $operation_currency->j_id=$let_other;
1070 $operation_currency->insert();
1071
1072 // insert into operation_currency bank
1073 $operation_currency=new Operation_currency_SQL($this->db);
1074 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
1075 $operation_currency->oc_vat_amount=0;
1076 $operation_currency->oc_price_unit=0;
1077 $operation_currency->j_id=$let_pay;
1078 $operation_currency->insert();
1079
1080 /* insert into jrn */
1081 $acc_pay->mt=$mt;
1082 $acc_pay->desc=(!isset($e_comm_paiement) || noalyss_strlentrim($e_comm_paiement) == 0) ?$e_comm:$e_comm_paiement;
1083
1084 // Add info for currency
1085 $acc_pay->currency_id=$p_currency_code;
1086 $acc_pay->currency_rate=$p_currency_rate;
1087 $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
1088
1089
1090 // insert into the table JRN
1091 $mp_jr_id=$acc_pay->insert_jrn();
1092 $this->payment_operation=$mp_jr_id;
1093 $acjrn->grpt_id=$acseq;
1094 $acjrn->update_internal_code($acinternal);
1095 // add an automatic PJ if ODS
1096 if ($acjrn->get_type()=="ODS") {
1097 $acc_pay->pj=$acjrn->guess_pj();
1098 $acc_pay->update_receipt();
1099 }
1100 $r1=$this->get_id($internal);
1101 $r2=$this->get_id($acinternal);
1102
1103 /*
1104 * add lettering
1105 */
1106 $oletter=new Lettering($this->db);
1107 $oletter->insert_couple($let_client,$let_other);
1108
1109 /* set the flag paid */
1110 $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
1111
1112 /* Reconcialiation */
1113 $rec=new Acc_Reconciliation($this->db);
1114 $rec->set_jr_id($r1);
1115 $rec->insert($r2);
1116 /*
1117 * save also into quant_fin
1118 */
1119
1120 /* get ledger property */
1121 $ledger=new Acc_Ledger_Fin($this->db,$acc_pay->jrn);
1122 $prop=$ledger->get_propertie();
1123
1124 /* if ledger is FIN then insert into quant_fin */
1125 if ( $prop['jrn_def_type'] == 'FIN' )
1126 {
1127 $ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1),$let_other);
1128 }
1129
1130
1131 }
1132 /*----------------------------------------------
1133 * Save the note
1134 ----------------------------------------------*/
1135 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
1136 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
1137 $acc_operation_note->setNote($p_array['jrn_note_input']);
1138 $acc_operation_note->setOperation_id( $this->jr_id);
1139 $acc_operation_note->save();
1140 }
1141 }//end try
1142 catch (Exception $e)
1143 {
1144 record_log($e);
1145 $this->db->rollback();
1146 throw $e;
1147 }
1148 $this->db->commit();
1149 return $internal;
1150 }
sql_string($p_string)
Fix the problem with the quote char for the database.
h( $row[ 'oa_description'])
$op jr_id
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.
compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
Compute the ND amount thanks the attribute of the concerned card.
inc_seq_pj()
increment the sequence for the pj
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
$row
!< database connextion
create_document($internal, $p_array)
create the invoice and saved it as attachment to the operation,
has_other_tax()
returns true if the ledger has an additional tax
update_internal_code($p_internal)
get_id($p_internal)
retrieve the jr_id thanks the internal code, do not change anything to the current object
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
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 insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
$check_periode
$other_tax_amount
Definition compute.php:88
const EXC_BALANCE
Definition constant.php:349
const ATTR_DEF_QUICKCODE
Definition constant.php:237
const ATTR_DEF_ACCOUNT
Definition constant.php:215
$_POST['ac']
Definition do.php:312
$str_file

References $_POST, $acompte, $array, $check_periode, $e, $e_date, $fiche, $g_parameter, $g_user, $i, $j_id, $ledger, $op, $oPeriode, $other_tax_amount, $p_array, $p_jrn, $poste, $prop, $r, $repo, $Res, Acc_Ledger\$row, $seq, $str_file, $tot_amount, $value, _, ATTR_DEF_ACCOUNT, ATTR_DEF_QUICKCODE, Acc_Tva\build(), Acc_Operation_Note\build_jrn_id(), Acc_Ledger\check_periode(), Acc_Ledger\compute_internal_code(), compute_no_deductible(), Acc_Ledger\create_document(), db, EXC_BALANCE, Acc_Ledger\get_id(), h, Acc_Ledger\has_other_tax(), Acc_Ledger\inc_seq_pj(), Stock_Goods\insert_goods(), insert_no_deductible(), jr_id, noalyss_strlentrim(), record_log(), sql_string(), and Acc_Ledger\update_internal_code().

+ Here is the call graph for this function:

◆ insert_no_deductible()

Acc_Ledger_Purchase::insert_no_deductible ( Acc_Compute $p_nd_amount,
Fiche $p_fiche,
$p_tva_both,
& $p_tot_debit,
Acc_Operation $p_acc_operation,
$p_group,
$idx )
private

Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.

Parameters
Acc_Compute$p_nd_amountcontent ND amount
Fiche$p_ficheCard of the Service
type$p_tva_both0 if TVA is normal or 1 if on both side
type$p_tot_debittotal debit
$p_acc_operationAcc_Operation for inserting into jrnx
$p_groupgroup for AC
$idxrow number
See also
Acc_Ledger_Purchase\insert

Definition at line 342 of file acc_ledger_purchase.class.php.

343 {
344 global $g_parameter;
345 if ($p_acc_operation->jrnx_id == 0) {
346 throw new Exception(__FILE__.__LINE__.'invalid acc_operation.j_id');
347 }
348 $source_j_id=$p_acc_operation->jrnx_id ;
349 /*
350 * Save all the no deductible
351 * ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
352 */
353 if ($p_nd_amount->amount_nd_rate != 0)
354 {
355 $dna_default = new Acc_Parm_Code($this->db, 'DNA');
356
357 /* save op. */
358 if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
359 {
360 $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND);
361 } else
362 {
363 $dna = $dna_default->p_value;
364 }
365 $dna = ($dna == '') ? $dna_default->p_value : $dna;
366
367 $p_acc_operation->type = 'd';
368 $p_acc_operation->amount = $p_nd_amount->amount_nd;
369 $p_acc_operation->poste = $dna;
370 $p_acc_operation->qcode = '';
371 $p_acc_operation->desc=$this->find_label($dna)." ND ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
372 if ($p_nd_amount->amount_nd > 0)
373 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
374 $j_id = $p_acc_operation->insert_jrnx();
375 }
376 /*
377 * ATTR_DEF_ACCOUNT_ND_PERSO
378 */
379 if ($p_nd_amount->amount_perso != 0)
380 {
381 $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
382
383 /* save op. */
384 $p_acc_operation->type = 'd';
386 {
387 $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_PERSO);
388 } else
389 {
390 $dna = $dna_default->p_value;
391 }
392 $dna = ($dna == '') ? $dna_default->p_value : $dna;
393
394 $p_acc_operation->amount = $p_nd_amount->amount_perso ;
395 $p_acc_operation->poste = $dna;
396 $p_acc_operation->qcode = '';
397 $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
398 if ($p_nd_amount->amount_perso> 0)
399 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
400 $j_id = $p_acc_operation->insert_jrnx();
401 }
402 if ($p_nd_amount->nd_vat != 0)
403 {
404 $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
405
406 /* save op. */
407 $p_acc_operation->type = 'd';
408 $p_acc_operation->qcode = '';
410 {
411 $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA_ND);
412 } else
413 {
414 $dna = $dna_default->p_value;
415 }
416 $dna = ($dna == '') ? $dna_default->p_value : $dna;
417
418 $p_acc_operation->amount = $p_nd_amount->nd_vat;
419 $p_acc_operation->poste = $dna;
420 $p_acc_operation->desc=$this->find_label($dna)." ND_TVA ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
421 $j_id = $p_acc_operation->insert_jrnx();
422 if ( $g_parameter->MY_ANALYTIC != "nu"
423 && $g_parameter->match_analytic($p_fiche->strAttribut(ATTR_DEF_ACCOUNT))
424 )
425 {
426 $op=new Anc_Operation($this->db);
427 $op->oa_group=$p_group;
428 $op->j_id=$j_id;
429 $op->oa_date=$p_acc_operation->date;
430
431 $op->oa_debit='t';
432 $op->oa_description=sql_string('ND_TVA');
433 $op->oa_jrnx_id_source=$source_j_id;
434 $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
435 }
436 if ($p_nd_amount->nd_vat> 0)
437 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
438
439 }
440 if ($p_nd_amount->nd_ded_vat != 0)
441 {
442 $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
443 /* save op. */
445 {
446 $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA);
447 } else
448 {
449 $dna = $dna_default->p_value;
450 }
451 $dna = ($dna == '') ? $dna_default->value : $dna;
452
453
454
455 $p_acc_operation->type = 'd';
456 $p_acc_operation->qcode = '';
457 $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
458 $p_acc_operation->poste = $dna;
459 $p_acc_operation->desc=$this->find_label($dna)." DED_TVA ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
460 if ($p_nd_amount->nd_ded_vat > 0)
461 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
462 $j_id = $p_acc_operation->insert_jrnx();
463 if ( $g_parameter->MY_ANALYTIC != "nu"
464 && $g_parameter->match_analytic($p_fiche->strAttribut(ATTR_DEF_ACCOUNT))
465 )
466 {
467 $op=new Anc_Operation($this->db);
468 $op->oa_group=$p_group;
469 $op->j_id=$j_id;
470 $op->oa_date=$p_acc_operation->date;
471
472 $op->oa_debit='t';
473 $op->oa_description=sql_string('DED_TVA ');
474 $op->oa_jrnx_id_source=$source_j_id;
475 $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
476 }
477 }
478 }
find_label($p_value)
Retrieve the label of an accounting.
insert_jrnx()
Insert into the table Jrn The needed data are :
const ATTR_DEF_ACCOUNT_ND_TVA_ND
Definition constant.php:242
const ATTR_DEF_ACCOUNT_ND
Definition constant.php:244
const ATTR_DEF_ACCOUNT_ND_TVA
Definition constant.php:241
const ATTR_DEF_ACCOUNT_ND_PERSO
Definition constant.php:243

References $_POST, $g_parameter, $idx, $j_id, $op, ATTR_DEF_ACCOUNT, ATTR_DEF_ACCOUNT_ND, ATTR_DEF_ACCOUNT_ND_PERSO, ATTR_DEF_ACCOUNT_ND_TVA, ATTR_DEF_ACCOUNT_ND_TVA_ND, ATTR_DEF_QUICKCODE, db, Fiche\empty_attribute(), Acc_Ledger\find_label(), Acc_Operation\insert_jrnx(), sql_string(), and Fiche\strAttribut().

Referenced by insert().

+ Here is the call graph for this function:

◆ verify_operation()

Acc_Ledger_Purchase::verify_operation ( $p_array)

verify that the data are correct before inserting or confirming

Parameters
anarray (usually $_POST)
Returns
String
Exceptions
Exceptionif an error occurs

we have to check also if the different accountings exist "ATTR_DEF_DEP_PRIV" "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE" "ATTR_DEF_TVA_NON_DEDUCTIBLE" "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"

Reimplemented from Acc_Ledger.

Definition at line 52 of file acc_ledger_purchase.class.php.

53 {
54 global $g_parameter,$g_user;
55
56 if (is_array($p_array ) == false || empty($p_array))
57 throw new Exception ("Array empty");
58 /*
59 * Check needed value
60 */
61 check_parameter($p_array,'p_jrn,e_date,e_client');
62
63 extract ($p_array, EXTR_SKIP);
64 /* check if we can write into this ledger */
65 if ( $g_user->check_jrn($p_jrn) != 'W' )
66 throw new Exception (_('Accès interdit'),20);
67
68
69 /* check for a double reload */
70 if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
71 throw new Exception (_('Double Encodage'),5);
72
73 /* check if there is a customer */
74 if ( noalyss_strlentrim($e_client)== 0 )
75 throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
76
77 /* check if the date is valid */
78 if ( isDate($e_date) == null )
79 {
80 throw new Exception(_('Date invalide'), 2);
81 }
82 $oPeriode=new Periode($this->db);
83 if ( $this->check_periode() == false || ! isset($p_array['period']))
84 {
85 $tperiode=$oPeriode->find_periode($e_date);
86 }
87 else
88 {
89 $tperiode=$period;
90 $oPeriode->p_id=$tperiode;
91 /* check that the datum is in the choosen periode */
92 list ($min,$max)=$oPeriode->get_date_limit($tperiode);
93 if ( cmpDate($e_date,$min) < 0 ||
94 cmpDate($e_date,$max) > 0)
95 throw new Exception(_('Date et periode ne correspondent pas'),6);
96 }
97 /* check if the periode is closed */
98 if ( $this->is_closed($tperiode)==1 )
99 {
100 throw new Exception(_('Periode fermee'),6);
101 }
102
103 /* check if we are using the strict mode */
104 if( $this->check_strict() == true)
105 {
106 /* if we use the strict mode, we get the date of the last
107 operation */
108 $last_date=$this->get_last_date();
109 if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
110 throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
111 .$last_date._(' vous ne pouvez pas encoder à une '.
112 ' date antérieure dans ce journal'),13);
113
114 }
115
116 /* check the account */
117 $fiche=new Fiche($this->db);
118 $fiche->get_by_qcode($e_client);
119 if ($fiche->get_f_enable() == '0')
120 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"),$e_client), 50);
121
122 if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
123 throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
124
125
126
127 /* get the account and explode if necessary */
128 $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
129 // if 2 accounts, take only the credit one for supplier
130 if ( strpos($sposte,',') != 0 )
131 {
132 $array=explode(',',$sposte);
133 $poste_val=$array[1];
134 }
135 else
136 {
137 $poste_val=$sposte;
138 }
139
140 /* The account exists */
141 $poste=new Acc_Account_Ledger($this->db,$poste_val);
142 if ( $poste->load() == false )
143 {
144 throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id.'] '._('n\'existe pas'),9);
145 }
146 /* Check if the card belong to the ledger */
147 $fiche=new Fiche ($this->db);
148 $fiche->get_by_qcode($e_client,'cred');
149 if ( $fiche->belong_ledger($p_jrn) !=1 )
150 throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
151
152 $nb=0;
153 //------------------------------------------------------
154 // The "Paid By" check
155 //------------------------------------------------------
156 if ($e_mp != 0 ) {
157 $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
158 // check for the currency , if we use a financial ledger and a card which is a bank account (with his own
159 // ledger , then the currency of the operation must be the same
160 $this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
161 }
162
163
164 //----------------------------------------
165 // foreach item
166 //----------------------------------------
167 for ($i=0;$i< $nb_item;$i++)
168 {
169 if ( noalyss_strlentrim(${'e_march'.$i})== 0) continue;
170
171 /* check if all card has a ATTR_DEF_ACCOUNT*/
172 $fiche=new Fiche($this->db);
173 $fiche->get_by_qcode(${'e_march'.$i});
174 if ($fiche->get_f_enable() == '0')
175 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"), ${'e_march' . $i}), 50);
176
177 /* check if amount are numeric and */
178 if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
179 throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide').' ['.${'e_march'.$i}.']',6);
180 if ( isNumber(${'e_quant'.$i}) == 0 )
181 throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
182
183 // Check if the given tva id is valid
184 if ( $g_parameter->MY_TVA_USE=='Y')
185 {
186 $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'});
187 if ($tva_rate->tva_id == -1)
188 throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
189 $tva_rate->load();
190 /*
191 * check if the accounting for VAT are valid
192 */
193 $a_poste=explode(',',$tva_rate->tva_poste);
194
195 if (
196 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1',array($a_poste[0])) == 0 )
197 throw new Exception(_(" La TVA ".$tva_rate->tva_label." utilise des postes comptables inexistants"));
198
199 }
200
201 if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
202 throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
203
204 /* get the account and explode if necessary */
205 $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
206 // if 2 accounts, take only the debit
207 if ( strpos($sposte,',') != 0 )
208 {
209 $array=explode(',',$sposte);
210 $poste_val=$array[0];
211 }
212 else
213 {
214 $poste_val=$sposte;
215 }
216
217 /* The account exists */
218 $poste=new Acc_Account_Ledger($this->db,$poste_val);
219 if ( $poste->load() == false )
220 {
221 throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable').' ['.$poste->id._('n\'existe pas'),9);
222 }
223 /* Check if the card belong to the ledger */
224 $fiche=new Fiche ($this->db);
225 $fiche->get_by_qcode(${'e_march'.$i});
226 if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
227 throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
228 /**
229 * we have to check also if the different accountings exist
230 "ATTR_DEF_DEP_PRIV"
231 "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
232 "ATTR_DEF_TVA_NON_DEDUCTIBLE"
233 "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
234 */
235 foreach (array(
240 {
241 if ( ! $fiche->empty_attribute($key[0]) && $fiche->empty_attribute($key[2]))
242 {
243 $a=new Acc_Parm_Code($this->db,$key[1]);
244 if ( $this->db->count_sql('select pcm_val from tmp_pcmn where pcm_val=$1',array($a->p_value))==0)
245 throw new Exception ($key[1]._("ce code n'a pas de poste comptable, créez ce poste : [".$a->p_value."]"));
246 }
247 if ( ! $fiche->empty_attribute($key[0]) && ! $fiche->empty_attribute($key[2]))
248 {
249 $nd_str=$fiche->strAttribut($key[2]);
250 if ( $nd_str != '')
251 {
252 $poste_nd=new Acc_Account_Ledger($this->db,$nd_str);
253 if ( $poste_nd->load() == false)
254 {
255 $nd_msg=sprintf(_("Pour la fiche %s, le compte contrepartie %s n'existe pas"),
256 $fiche->getName(),$poste_nd->id);
257 $nd_msg=h($nd_msg);
258 throw new Exception ($nd_msg);
259 }
260 }
261 }
262 }
263 if ( ${"e_quant".$i} != 0 && trim(${"e_quant".$i}) !="" ) {$nb++;}
264 }
265
266 if ( $nb == 0 )
267 throw new Exception(_('Il n\'y a aucune marchandise'),12);
268
269 // check payment date
270 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
271 throw new Exception(_('Date de paiement invalide'),13);
272
273 }
274 // check that MP is in a not closed and exists
275 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == $mp_date ) {
276 $periode=new Periode($this->cn);
277 $periode->find_periode($mp_date);
278 $periode->set_ledger($this->id);
279 if ( $periode->is_closed() ) {
280 throw new Exception(_("Période fermée")." $mp_date ");
281 }
282
283 }
284 // check limit date
285 if ( isset ($e_ech) && trim ($e_ech)!="" && isDate($e_ech) == null )
286 {
287 throw new Exception(_('Date échéance invalide'),14);
288
289 }
290 // Check currency_rate if valid
291 if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
292 throw new Exception(_('Taux devise invalide'),15);
293 }
294 $this->check_currency_setting($p_currency_code);
295 }
isNumber($p_int)
isDate($p_date)
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
catch(Exception $e) $tva_rate
for($i=0; $i< count($plan); $i++)( $j==0) $a_poste
$input_from cn
$nb
!< type of the ledger ACH ODS FIN VEN or GL
check_currency($p_qcode_payment, $p_currency_id)
When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo...
is_closed($p_periode)
check if the current ledger is closed
check_payment($e_mp, $e_mp_qcode)
check if the payment method is valid
get_last_date()
get the date of the last operation
check_strict()
Check if a Dossier is using the strict mode or not.
check_currency_setting($p_currency_code)
Check that the currency code does exist and the setting of the folder is correct.
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...

References $a, $a_poste, $array, $e_date, $fiche, $g_parameter, $g_user, $i, $max, $min, Acc_Ledger\$nb, $oPeriode, $p_array, $p_jrn, $periode, $poste, $tva_rate, _, ATTR_DEF_ACCOUNT, ATTR_DEF_ACCOUNT_ND, ATTR_DEF_ACCOUNT_ND_PERSO, ATTR_DEF_ACCOUNT_ND_TVA, ATTR_DEF_ACCOUNT_ND_TVA_ND, ATTR_DEF_DEP_PRIV, ATTR_DEF_DEPENSE_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE, ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP, Acc_Tva\build(), Acc_Ledger\check_currency(), Acc_Ledger\check_currency_setting(), check_parameter(), Acc_Ledger\check_payment(), Acc_Ledger\check_periode(), Acc_Ledger\check_strict(), cmpDate(), cn, db, Acc_Ledger\get_last_date(), h, Acc_Ledger\is_closed(), isDate(), isNumber(), and noalyss_strlentrim().

+ Here is the call graph for this function:

Field Documentation

◆ $payment_operation

Acc_Ledger_Purchase::$payment_operation
private

Definition at line 38 of file acc_ledger_purchase.class.php.


The documentation for this class was generated from the following file: