Exemplo n.º 1
0
 /**
  * Show custom information box.
  *
  * @param WP_Post $post
  * @param array   $metabox
  * @return
  */
 public static function show_information_meta_box($post, $metabox)
 {
     // For client creation
     add_thickbox();
     $args = array('post_type' => SI_Client::POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => -1, 'fields' => 'ids');
     $clients = get_posts($args);
     $client_options = array();
     foreach ($clients as $client_id) {
         $client_options[$client_id] = get_the_title($client_id);
     }
     $invoice = SI_Invoice::get_instance($post->ID);
     $status = is_a($invoice, 'SI_Invoice') && $invoice->get_status() != 'auto-draft' ? $invoice->get_status() : SI_Invoice::STATUS_TEMP;
     $due_date = is_a($invoice, 'SI_Invoice') ? $invoice->get_due_date() : current_time('timestamp') + 60 * 60 * 24 * 30;
     $expiration_date = is_a($invoice, 'SI_Invoice') ? $invoice->get_expiration_date() : current_time('timestamp') + 60 * 60 * 24 * 30;
     $issue_date = is_a($invoice, 'SI_Invoice') ? $invoice->get_issue_date() : strtotime($post->post_date);
     $estimate_id = is_a($invoice, 'SI_Invoice') ? $invoice->get_estimate_id() : 0;
     $invoice_id = is_a($invoice, 'SI_Invoice') ? $invoice->get_invoice_id() : '00001';
     $po_number = is_a($invoice, 'SI_Invoice') ? $invoice->get_po_number() : '';
     $client_id = is_a($invoice, 'SI_Invoice') ? $invoice->get_client_id() : 0;
     $deposit = is_a($invoice, 'SI_Invoice') ? $invoice->get_deposit() : '';
     $discount = is_a($invoice, 'SI_Invoice') ? $invoice->get_discount() : '';
     $tax = is_a($invoice, 'SI_Invoice') ? $invoice->get_tax() : '';
     $tax2 = is_a($invoice, 'SI_Invoice') ? $invoice->get_tax2() : '';
     $currency = is_a($invoice, 'SI_Invoice') ? $invoice->get_currency() : '';
     self::load_view('admin/meta-boxes/invoices/information', array('id' => $post->ID, 'post' => $post, 'invoice' => $invoice, 'status' => $status, 'status_options' => SI_Invoice::get_statuses(), 'estimate_id' => $estimate_id, 'invoice_id' => $invoice_id, 'expiration_date' => $expiration_date, 'due_date' => $due_date, 'issue_date' => $issue_date, 'client_id' => $client_id, 'client_options' => $client_options, 'clients' => $clients, 'po_number' => $po_number, 'deposit' => $deposit, 'discount' => $discount, 'tax' => $tax, 'tax2' => $tax2, 'currency' => $currency), false);
     // add the client modal
     self::load_view('admin/meta-boxes/clients/creation-modal', array('fields' => SI_Clients::form_fields(false)));
 }
 public static function maybe_create_new_invoices()
 {
     $args = array('post_type' => SI_Invoice::POST_TYPE, 'post_status' => array_keys(SI_Invoice::get_statuses()), 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array('relation' => 'AND', array('key' => self::$meta_keys['is_recurring'], 'value' => 1, 'compare' => '='), array('key' => self::$meta_keys['clone_time'], 'value' => array(strtotime('Last year'), current_time('timestamp')), 'compare' => 'BETWEEN'), array('key' => self::$meta_keys['cloned_from'], 'compare' => 'NOT EXISTS')));
     $invoice_ids = get_posts($args);
     foreach ($invoice_ids as $invoice_id) {
         $cloned_post_id = self::clone_post($invoice_id, SI_Invoice::STATUS_PENDING, SI_Invoice::POST_TYPE);
         // Issue date is today.
         $cloned_invoice = SI_Invoice::get_instance($cloned_post_id);
         $cloned_invoice->set_issue_date(time());
         // Due date is in the future
         $due_date = apply_filters('si_new_recurring_invoice_due_date_in_days', 14);
         $cloned_invoice->set_due_date(time() + 60 * 60 * 24 * $due_date);
         // adjust the clone time after the next invoice
         self::set_clone_time($invoice_id, current_time('timestamp'));
         self::set_parent($cloned_post_id, $invoice_id);
         do_action('si_recurring_invoice_created', $invoice_id, $cloned_post_id);
     }
 }