Changeset 1424199
- Timestamp:
- 05/25/2016 05:17:57 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
woocommerce-superfaktura/trunk/class-wc-superfaktura.php
r1424167 r1424199 24 24 * @var string 25 25 */ 26 protected $version = '1.5. 4';26 protected $version = '1.5.5'; 27 27 28 28 /** … … 249 249 } 250 250 251 public function sf_clean_invoice_items($order, $api) 252 { 253 $invoice_id = (int)get_post_meta($order->id, 'wc_sf_internal_id', true); 251 public function sf_clean_invoice_items($invoice_id, $api) 252 { 254 253 $response = $api->invoice($invoice_id); 255 254 if(!isset($response->error) || $response->error==0) … … 265 264 public function sf_new_invoice($order_id) 266 265 { 266 $order = new WC_Order($order_id); 267 268 foreach( array('regular','proforma') as $type ) 269 { 270 if ( ! $invoice_status = $this->generate_invoice_status($order->payment_method,$type) ) 271 continue; 272 273 if ( $invoice_status != $order->status ) 274 continue; 275 276 $this->sf_generate_invoice( $order, $type ); 277 } 278 } 279 280 private function sf_generate_invoice( $order, $type ) { 267 281 $edit = false; 268 $order = new WC_Order($order_id);269 282 $api = $this->sf_api(); 270 283 271 $sf_id = get_post_meta($order->id, 'wc_sf_internal_id', true); 284 $sf_id = get_post_meta($order->id, 'wc_sf_internal_' . $type . '_id', true); 285 286 // plugin-update checking code 287 if ( ! $sf_id ) { 288 $old_sf_id = get_post_meta( $order->id, 'wc_sf_internal_id', true ); 289 if ( $old_sf_id ) { 290 // if there is generated regular invoice (link), then it's regular id 291 if ( get_post_meta( $order->id, 'wc_sf_invoice_regular', true ) ) { 292 update_post_meta( $order->id, 'wc_sf_internal_regular_id', $old_sf_id ); 293 // use only if we are generating regular invoice 294 if ( 'regular' === $type ) { 295 $sf_id = $old_sf_id; 296 } 297 } 298 // else if there is generated proforma invoice (link), then it's proforma id 299 elseif ( get_post_meta( $order->id, 'wc_sf_invoice_proforma', true ) ) { 300 update_post_meta( $order->id, 'wc_sf_internal_proforma_id', $old_sf_id ); 301 // use only if we are generating proforma invoice 302 if ( 'proforma' === $type ) { 303 $sf_id = $old_sf_id; 304 } 305 } 306 } 307 } 308 // --------------------------- 309 272 310 if(!empty($sf_id)) 273 311 { … … 275 313 return false; 276 314 277 $this->sf_clean_invoice_items($ order, $api);315 $this->sf_clean_invoice_items($sf_id, $api); 278 316 $edit = true; 279 317 } … … 512 550 } 513 551 514 foreach( array('regular','proforma') as $type ) 515 { 516 if ( ! $invoice_status = $this->generate_invoice_status($order->payment_method,$type) ) 517 continue; 518 519 if ( $invoice_status != $order->status ) 520 continue; 552 if($edit) 553 { 554 $api->setInvoice(array( 555 'type' => $type, 556 'id' => $sf_id, 557 )); 558 559 $response = $api->edit(); 560 } 561 else 562 { 563 $invoice_id = get_option('woocommerce_sf_invoice_custom_num')=='yes' ? $this->generate_invoice_id($order,$type) : ''; 564 565 $api->setInvoice(array( 566 'type' => $type, 567 'invoice_no_formatted' => $invoice_id, 568 )); 569 570 $response = $api->save(); 571 } 572 573 if( $response->error === 0 ) 574 { 575 $internal_id = $response->data->Invoice->id; 576 577 update_post_meta($order->id, 'wc_sf_internal_' . $type . '_id', $internal_id); 578 579 $pdf = $api::SFAPI_URL.'/invoices/pdf/'.$internal_id.'/token:'.$response->data->Invoice->token; 580 581 update_post_meta($order->id, 'wc_sf_invoice_'.$type, $pdf); 521 582 522 583 if($edit) 523 584 { 524 $api->setInvoice(array( 525 'type' => $type, 526 'id' => (int)get_post_meta($order->id, 'wc_sf_internal_id', true) 527 )); 528 529 $response = $api->edit(); 530 } 531 else 532 { 533 $invoice_id = get_option('woocommerce_sf_invoice_custom_num')=='yes' ? $this->generate_invoice_id($order,$type) : ''; 534 535 $api->setInvoice(array( 536 'type' => $type, 537 'invoice_no_formatted' => $invoice_id, 538 )); 539 540 $response = $api->save(); 541 } 542 543 if( $response->error === 0 ) 544 { 545 $internal_id = $response->data->Invoice->id; 546 547 update_post_meta($order->id, 'wc_sf_internal_id', $internal_id); 548 549 $pdf = $api::SFAPI_URL.'/invoices/pdf/'.$internal_id.'/token:'.$response->data->Invoice->token; 550 551 update_post_meta($order->id, 'wc_sf_invoice_'.$type, $pdf); 552 553 if($edit) 554 { 555 556 } 557 } 558 else 559 { 560 $pdf = $order->get_view_order_url(); //? 561 } 585 586 } 587 } 588 else 589 { 590 $pdf = $order->get_view_order_url(); //? 562 591 } 563 592 }
Note: See TracChangeset
for help on using the changeset viewer.