[Vtigercrm-developers] Sales orders please help me.
Arnold den Boer
arnold at ardebo.nl
Wed Mar 26 09:26:27 GMT 2014
I did,
This is my file.
What am I doing wrong?
<?php
/***************************************************************************
******
** The contents of this file are subject to the vtiger CRM Public License
Version 1.0
* ("License"); You may not use this file except in compliance with the
License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
****************************************************************************
****/
require_once('include/utils/utils.php');
require_once('include/logging.php');
// Get the list of Invoice for which Recurring is enabled.
global $adb, $log;
$log =& LoggerManager::getLogger('RecurringInvoice');
$log->debug("invoked RecurringInvoice");
$sql="SELECT vtiger_salesorder.salesorderid, recurring_frequency,
start_period, end_period, last_recurring_date,
payment_duration, invoice_status FROM
vtiger_salesorder
INNER JOIN vtiger_crmentity ON
vtiger_salesorder.salesorderid = vtiger_crmentity.crmid AND
vtiger_crmentity.deleted = 0
INNER JOIN vtiger_invoice_recurring_info ON
vtiger_salesorder.salesorderid = vtiger_invoice_recurring_info.salesorderid
WHERE DATE_FORMAT(start_period,'%Y-%m-%d') <=
'".date('Y-m-d')."' AND DATE_FORMAT(end_period,'%Y-%m-%d') >=
'".date('Y-m-d')."'";
$result = $adb->pquery($sql, array());
$no_of_salesorder = $adb->num_rows($result);
for($i=0; $i<$no_of_salesorder;$i++) {
$salesorder_id = $adb->query_result($result,
$i,'salesorderid');
$start_period = $adb->query_result($result,
$i,'start_period');
$end_period = $adb->query_result($result, $i,'end_period');
$last_recurring_date = $adb->query_result($result,
$i,'last_recurring_date');
$recurring_frequency = $adb->query_result($result,
$i,'recurring_frequency');
if ($last_recurring_date == NULL || $last_recurring_date ==
'' || $last_recurring_date == '0000-00-00') {
$last_recurring_date = $start_period;
}
$currentRecurringDate = $last_recurring_date;
if(strtotime($currentRecurringDate) >
strtotime($end_period)) {
continue;
}
switch(strtolower($recurring_frequency)) {
case 'daily' : $period
= '+1 day'; break;
case 'weekly' : $period =
'+1 week'; break;
case 'monthly' : $period = '+1
month'; break;
case 'quarterly': $period = '+3
month'; break;
case 'yearly' : $period =
'+1 year'; break;
default :
$period = '';
}
if (strtotime($currentRecurringDate) <=
strtotime(date('Y-m-d'))) {
list($y, $m, $d) = explode('-',
$last_recurring_date);
$nextRecurringDate = date('Y-m-d',
strtotime($period, mktime(0, 0, 0, $m, $d, $y)));
} else {
$nextRecurringDate = $currentRecurringDate;
}
if(strtotime($nextRecurringDate) ==
strtotime(date('Y-m-d'))) {
createInvoice($salesorder_id);
$adb->pquery('UPDATE
vtiger_invoice_recurring_info SET last_recurring_date = ? WHERE salesorderid
= ?', array($nextRecurringDate, $salesorder_id));
}
}
/* Function to create a new Invoice using the given Sales Order id */
function createInvoice($salesorder_id) {
require_once('include/utils/utils.php');
require_once('modules/SalesOrder/SalesOrder.php');
require_once('modules/Invoice/Invoice.php');
require_once('modules/Users/Users.php');
global $log, $adb;
global $current_user;
// Payment duration in days
$payment_duration_values = Array(
'net 30 days' => '30',
'net 45 days' => '45',
'net 60 days' => '60'
);
if(!$current_user) {
$current_user = new Users();
$current_user->id = 1;
$current_user =
$current_user->retrieve_entity_info($current_user->id, "Users");
}
$so_focus = new SalesOrder();
$so_focus->id = $salesorder_id;
$so_focus->retrieve_entity_info($salesorder_id,"SalesOrder");
foreach($so_focus->column_fields as $fieldname=>$value) {
$so_focus->column_fields[$fieldname] =
decode_html($value);
}
$focus = new Invoice();
// This will only fill in the basic columns from SO to
Invoice and also Update the SO id in new Invoice
$focus =
getConvertSoToInvoice($focus,$so_focus,$salesorder_id);
// Pick up the Payment due date based on the Configuration
in SO
$payment_duration =
$so_focus->column_fields['payment_duration'];
$due_duration =
$payment_duration_values[trim(strtolower($payment_duration))];
$durationinsec =
mktime(0,0,0,date('m'),date('d')+$due_duration,date('Y'));
// Cleanup focus object, to duplicate the Invoice.
$focus->id = '';
$focus->mode = '';
$focus->column_fields['invoicestatus'] =
$so_focus->column_fields['invoicestatus'];
$focus->column_fields['invoicedate'] = date('Y-m-d');
$focus->column_fields['duedate'] = date('Y-m-d',
$durationinsec);
// Additional SO fields to copy -> Invoice field name mapped
to equivalent SO field name
$invoice_so_fields = Array (
'txtAdjustment' => 'txtAdjustment',
'hdnSubTotal' => 'hdnSubTotal',
'hdnGrandTotal' => 'hdnGrandTotal',
'hdnTaxType' => 'hdnTaxType',
'hdnDiscountPercent' => 'hdnDiscountPercent',
'hdnDiscountAmount' => 'hdnDiscountAmount',
'hdnS_H_Amount' => 'hdnS_H_Amount',
'assigned_user_id' => 'assigned_user_id',
'currency_id' => 'currency_id',
'conversion_rate' => 'conversion_rate',
);
foreach($invoice_so_fields as $invoice_field => $so_field) {
$focus->column_fields[$invoice_field] =
$so_focus->column_fields[$so_field];
}
$focus->_salesorderid = $salesorder_id;
$focus->_recurring_mode = 'recurringinvoice_from_so';
$focus->save("Invoice");
}
?>
Van: vtigercrm-developers-bounces at lists.vtigercrm.com
[mailto:vtigercrm-developers-bounces at lists.vtigercrm.com] Namens Uma S
Verzonden: dinsdag 25 maart 2014 12:20
Aan: vtigercrm-developers at lists.vtigercrm.com;
vtigercrm-developers at lists.vtigercrm.com
Onderwerp: Re: [Vtigercrm-developers] Sales orders please help me.
Hi,
Please pick the changeset updated in tracker
<http://trac.vtiger.com/cgi-bin/trac.cgi/ticket/7938> and check.
On Mon, Mar 24, 2014 at 8:11 PM, Arnold den Boer <arnold at ardebo.nl
<mailto:arnold at ardebo.nl> > wrote:
It is still not working for me.
Is the change bellow the only thing you changed?
-----Oorspronkelijk bericht-----
Van: vtigercrm-developers-bounces at lists.vtigercrm.com
<mailto:vtigercrm-developers-bounces at lists.vtigercrm.com>
[mailto:vtigercrm-developers-bounces at lists.vtigercrm.com
<mailto:vtigercrm-developers-bounces at lists.vtigercrm.com> ] Namens apcloic
Verzonden: dinsdag 4 maart 2014 18:31
Aan: vtigercrm-developers at lists.vtigercrm.com
<mailto:vtigercrm-developers at lists.vtigercrm.com> ;
vtigercrm-developers at lists.vtigercrm.com
<mailto:vtigercrm-developers at lists.vtigercrm.com>
Onderwerp: Re: [Vtigercrm-developers] Sales orders please help me.
Ok, I finally found how to make it work by replacing the following code :
With :
So basically, I've simply put createInvoice($salesorder_id) after
$adb->pquery and now invoice is created + last_recurring_date is updated.
Regards ;)
--
View this message in context:
http://vtiger-crm.2324883.n4.nabble.com/Vtigercrm-developers-Sales-orders-pl
<http://vtiger-crm.2324883.n4.nabble.com/Vtigercrm-developers-Sales-orders-p
lease-help-me-tp9148p9659.html>
ease-help-me-tp9148p9659.html
Sent from the vtigercrm-developers mailing list archive at Nabble.com.
_______________________________________________
http://www.vtiger.com/
_______________________________________________
http://www.vtiger.com/
--
With
Best Regards
Uma.S
Vtiger Team
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20140326/50c317d4/attachment-0001.html>
More information about the vtigercrm-developers
mailing list