Exemple #1
0
    $customers = $DB->GetALL("SELECT * FROM customerassignments WHERE customergroupid=" . $groups[0]['id']);
    foreach ($customers as $customer) {
        $name = $LMS->GetCustomerName($customer['customerid']);
        printf("%4d: %s\n", $customer['customerid'], $name);
    }
} else {
    $customers = $DB->GetAll('SELECT * FROM customers WHERE status=3 and deleted=0');
    if (count($customers) and !$test) {
        $msgid = create_message($tmpl['name'], $tmpl['message']);
    }
    $razem = 0;
    $ilosc = 0;
    $tresc = '';
    foreach ($customers as $customer) {
        $id = $customer['id'];
        $balance = $LMS->GetCustomerBalance($id);
        $covenant = 0;
        $oplata = 0;
        $assignments = $LMS->GetCustomerAssignments($id, true);
        #if ($customer['id']==2) print_r($assignments);
        if (is_array($assignments)) {
            foreach ($assignments as $assignment) {
                if ($assignment['liabilityid']) {
                    #print $assignment['period']."\n";
                    if ($assignment['period'] == 'rocznie' and $assignment['at'] == $yearday or $assignment['period'] == 'jednorazowo' and $assignment['at'] == $mday) {
                        $covenant += $assignment['discounted_value'];
                    }
                    #else echo "Poza zakresem!: '".$assignment['at']."'/'".$yearday."'\n";
                } elseif ($assignment['datefrom'] == 0 or $assignment['datefrom'] < time()) {
                    if ($assignment['period'] == 'rocznie') {
                        $covenant += 11 * $assignment['discounted_value'];
Exemple #2
0
    die("Fatal error: Can't init curl library!\n");
}
$query = "SELECT d.id, d.number, d.cdate, c.email, d.name, d.customerid, n.template \n\t\tFROM documents d \n\t\tLEFT JOIN customers c ON c.id = d.customerid \n\t\tLEFT JOIN numberplans n ON n.id = d.numberplanid \n\t\tWHERE c.deleted = 0 AND d.type IN (1,3) AND c.email <> '' AND c.invoicenotice = 1 " . (!empty($invoiceid) ? "AND d.id = " . $invoiceid : "AND d.cdate >= {$daystart} AND d.cdate <= {$dayend}") . (!empty($groupnames) ? $customergroups : "") . " ORDER BY d.number";
$docs = $DB->GetAll($query);
if (!empty($docs)) {
    foreach ($docs as $doc) {
        curl_setopt_array($ch, array(CURLOPT_URL => $lms_url . '/?m=invoice&override=1&original=1&id=' . $doc['id'] . '&loginform[login]=' . $lms_user . '&loginform[pwd]=' . $lms_password, CURLOPT_HTTPGET => TRUE, CURLOPT_POST => FALSE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_COOKIEJAR => COOKIE_FILE, CURLOPT_COOKIEFILE => COOKIE_FILE, CURLOPT_SSLVERSION => 3, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_USERAGENT => USER_AGENT));
        $res = curl_exec($ch);
        if (!empty($res)) {
            $custemail = !empty($debug_email) ? $debug_email : $doc['email'];
            $invoice_number = !empty($doc['template']) ? $doc['template'] : '%N/LMS/%Y';
            $body = $mail_body;
            $subject = $mail_subject;
            $invoice_number = docnumber($doc['number'], $invoice_number, $doc['cdate'] + date('Z'));
            $body = preg_replace('/%invoice/', $invoice_number, $body);
            $body = preg_replace('/%balance/', $LMS->GetCustomerBalance($doc['customerid']), $body);
            $day = sprintf("%02d", $day);
            $month = sprintf("%02d", $month);
            $year = sprintf("%04d", $year);
            $body = preg_replace('/%today/', $year . "-" . $month . "-" . $day, $body);
            $body = str_replace('\\n', "\n", $body);
            $subject = preg_replace('/%invoice/', $invoice_number, $subject);
            $filename = preg_replace('/%docid/', $doc['id'], $invoice_filename);
            if (!$quiet || $test) {
                printf("Invoice No. {$invoice_number} for " . $doc['name'] . " <{$custemail}>\n");
            }
            if (!$test) {
                $headers = array('From' => $from, 'To' => qp_encode($doc['name']) . ' <' . $custemail . '>', 'Subject' => $subject);
                if (!empty($notify_email)) {
                    $headers['Cc'] = $notify_email;
                }