dongyuanguang3893 2015-03-16 18:04
浏览 30

如何按x天重复重复发票然后停止

I am trying to update my ( Recurring Invoice ) setup but i am running into a little bit of trouble.

I am trying to make it where i do this...

  1. enter date ( which is the starting date of the recurrence )
  2. enter how it will recur ( weekly.bi-weekly and so on..)
  3. this is where the issue starts for me.... ( enter how many times it will recur for and then stop the invoice recurring) .. thanks in advance

<?php require 'initapp.php'; $self='invoice-recurring.php'; $rself='all-recurring-invoice.php'; if (isset($_POST['submit'])){

$cid = _post('client');
if ($cid=='' OR $cid=='0'){
    conf($self,'e','Client Name is Required.');
}
$idate = _post('date');
$date=date("Y-m-d", strtotime($idate));

if ($date==''){
    conf($self,'e','Date is Required.');
}

$item = _post('item');
if ($item==''){
    conf($self,'e','Item Name is Required.');
}

$note = _post('note');
$note=html_entity_decode($note);
$recurring = _post('frequency');
if ($recurring==''){
    conf($self,'e','Frequency is Required.');
} //starts added on 3-7-2015 //$occurance = _post('occurance'); // if ($occurance==''){ //      conf($self,'e','Occurance is Required.'); //  } //stops

$price= _post('price');
if ($price==''){
    conf($self,'e','Price is Required.');
}

$discount=_post('discount');

$disc_calculate=($discount*$price/100);

$tax=_post('tax'); if ($tax!='0'){ $tax = ORM::for_table('taxes')->find_one($tax); $trate = $tax['rate']; $tname = $tax['name']; $ttype = $tax['type']; if ($ttype=='Excluded'){ $tval = ($price*$trate)/100; $intotal = $price+$tval;

  }
  else {
      $tval = ($price*$trate)/100;
      $intotal = $price-$tval; 
  }
}
else{
  $intotal=$price;
  $tval='0';
  $tname='None';
}


$created = $date;
$add_days =$recurring;
$paiddate = date('Y-m-d',strtotime($date) + (24*3600*$add_days)); //add or delete * $occurance added on 3-7-2015 //$emailnotify='Yes'; $emailnotify = $aclient->emailnotify;//added on 2-25-2015

$intotal=$intotal-$disc_calculate; $paymentmethod=_post('paymentmethod');

$d = ORM::for_table('invoices')->create();
        $d->userid = $cid;
$d->iteam = $item;
$d->created = $date;
         $d->duedate = $date;
        $d->nextduedate=$paiddate;
$d->datepaid=$date;
$d->subtotal = $price;
        $d->total = $intotal;
        $d->discount = $discount;
        $d->paymentmethod=$paymentmethod;
$d->note = $note;
        $d->tax=$tval;
        $d->taxname=$tname;
$d->status = 'Unpaid';
        $d->recurring = $recurring;
      //$d->occurance = $occurance;//added on 3-7-2015
$d->save();
$invoiceid= $d->id();

if ($emailnotify=='Yes'){
    $sysEmail=appconfig('Email');
    $sysCompany=appconfig('CompanyName');
    $sysUrl= appconfig('sysUrl');
    $d= ORM::for_table('email_templates')->where('tplname', 'Customer Invoice Created')->find_one();
    $cl = ORM::for_table('accounts')->find_one($cid);
    $name = $cl['name'];
    $email = $cl['email'];

    $template = $d['message'];
    $subject = $d['subject'];
    $send = $d['send'];
    $data = array('name' => $name,
        'logo'=> '<img width="61" height="76" border="0" src="'.$sysUrl.'/assets/uploads/logo.jpg">',
        'business_name'=> $sysCompany,
        'invoice_id'=> $invoiceid,
        'invoice_item'=> $item,
        'invoice_amount'=> $intotal,
        'sys_url' => $sysUrl
    );
    $message = _render($template,$data);

    $mail_subject = _render($subject,$data);


    $body = $message;
    if ($send=='1'){

        $smtp=ORM::for_table('smtp_setting')->find_one('1');
        $smtp_status=$smtp['status'];

        if($smtp_status!='1'){

            require ('../lib/pnp/email/class.phpmailer.php') ;

            $mail = new PHPMailer();
            $mail->SetFrom($sysEmail, $sysCompany);
            $mail->AddReplyTo($sysEmail, $sysCompany);
            $mail->AddAddress($email, $name);
            $mail->Subject    = $mail_subject;
            $mail->MsgHTML($body);
            $mail->Send();
        }else{
            require ('../lib/plugin/PHPMailer/PHPMailerAutoload.php');
            $host_name=$smtp['host_name'];
            $username=$smtp['username'];
            $password=$smtp['password'];
            $port=$smtp['port'];

            $mail = new PHPMailer;
            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = "$host_name";  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = "$username";                 // SMTP username
            $mail->Password ="$password";                           // SMTP password
            $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = "$port";

            $mail->SetFrom($sysEmail, $sysCompany);
            $mail->AddReplyTo($sysEmail, $sysCompany);
            $mail->AddAddress($email, $name);
            $mail->Subject    = $mail_subject;
            $mail->MsgHTML($body);
            $mail->Send();

        }
    }

}


    conf("invoice-manage.php?_inid=$invoiceid",'s','Recurring Invoice Add Successfully'); } conf($self,'e','Invoice does not Create Successfully'); ?>
  • 写回答

1条回答 默认 最新

  • duanbo1659 2015-03-16 18:43
    关注

    Most likely you need the time and/or lenght/duration of the event. You can use cron for it or send me a PM I have written a php script.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端