Skip to content

Commit b98b0e4

Browse files
committed
Added support for Cost Centers (Centros de costo) in invoice generation
Added Cost Center configuration in settings
1 parent dfd02c6 commit b98b0e4

6 files changed

Lines changed: 65 additions & 13 deletions

File tree

includes/admin/other_settings.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
return $new_seller;
77
});
88

9+
$cost_centers = $this->get_data_options('Integration_Alegra_WC::get_cost_centers', function($new_cost_center, $cost_center){
10+
if($cost_center["status"] !== 'active') return $new_cost_center;
11+
$new_cost_center[$cost_center["id"]] = $cost_center["name"];
12+
return $new_cost_center;
13+
});
14+
915
$taxes = $this->get_data_options('Integration_Alegra_WC::get_taxes', function($new_tax, $tax){
1016
if($tax["status"] !== 'active') return $new_tax;
1117
$new_tax[$tax["id"]] = "{$tax["name"]} - {$tax["percentage"]}%";
1218
return $new_tax;
1319
});
1420

15-
// Agregar opción por defecto sin impuesto
16-
$taxes = array_merge(
17-
array('' => __('Sin impuesto')),
18-
$taxes
19-
);
20-
2121
return [
2222
'invoice' => array(
2323
'title' => __( 'Facturas de ventas' ),
@@ -50,6 +50,14 @@
5050
'description' => __( 'Vendedor asociado a la factura' ),
5151
'desc_tip' => false
5252
),
53+
'cost_center_generate_invoice' => array(
54+
'title' => __( 'Centro de costo' ),
55+
'type' => 'select',
56+
'options' => $cost_centers,
57+
'default' => '',
58+
'description' => __( 'Centro de costo asociado a la factura' ),
59+
'desc_tip' => false
60+
),
5361
'client' => array(
5462
'title' => __( 'Clientes' ),
5563
'type' => 'title'

includes/class-integration-alegra-wc-plugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,14 @@ public function register_additional_checkout_fields(): void
243243
woocommerce_register_additional_checkout_field(
244244
array(
245245
'id' => 'document/dni',
246-
'label' => 'Número de documento',
246+
'label' => 'Número de documento (sin DV)',
247247
'optionalLabel' => '1055666777',
248248
'location' => 'address',
249249
'required' => true,
250250
'attributes' => array(
251251
'autocomplete' => 'billing_dni',
252252
'aria-describedby' => 'some-element',
253-
'aria-label' => 'Número de documento',
253+
'aria-label' => 'Número de documento (sin DV)',
254254
'pattern' => '[0-9]{5,12}'
255255
)
256256
),
@@ -281,7 +281,7 @@ public function document_woocommerce_fields($fields): array
281281
);
282282

283283
$fields['dni'] = array(
284-
'label' => __('Número de documento'),
284+
'label' => __('Número de documento (sin DV)'),
285285
'placeholder' => _x('', 'placeholder'),
286286
'required' => true,
287287
'clear' => false,

includes/class-integration-alegra-wc.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ public static function get_instance(): ?Client
4949
return self::$alegra;
5050
}
5151

52+
public static function get_cost_centers(): array
53+
{
54+
$cost_centers = [];
55+
56+
if (!self::get_instance()) return $cost_centers;
57+
58+
try{
59+
$query = [
60+
"status" => "active"
61+
];
62+
$cost_centers = self::get_instance()->getCostCenters($query);
63+
}catch(Exception $exception){
64+
integration_alegra_wc_smp()->log($exception->getMessage());
65+
}
66+
67+
return $cost_centers;
68+
}
69+
5270
public static function get_sellers(): array
5371
{
5472
$sellers = [];
@@ -227,6 +245,11 @@ public static function generate_invoice($order_id, $previous_status, $next_statu
227245
];
228246

229247
$data_invoice = array_merge($data_invoice, $seller);
248+
249+
if ( ! empty( self::$integration_settings->cost_center_generate_invoice ) ) {
250+
$data_invoice['costCenter'] = self::$integration_settings->cost_center_generate_invoice;
251+
}
252+
230253
if(self::$integration_settings->debug === 'yes') {
231254
integration_alegra_wc_smp()->log('createInvoice: ' . print_r($data_invoice, true));
232255
}

integration-alegra-woo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
/**
33
* Plugin Name: Integration Alegra Woocommerce
4-
* Description: Integración del sistama contable y de facturación Alegra para Woocoommerce
5-
* Version: 0.0.14
4+
* Description: Integración del sistema contable y de facturación Alegra para Woocommerce
5+
* Version: 0.0.15
66
* Author: Saúl Morales Pacheco
77
* Author URI: https://saulmoralespa.com
88
* License: GNU General Public License v3.0
@@ -20,7 +20,7 @@
2020
}
2121

2222
if(!defined('INTEGRATION_ALEGRA_WC_SMP_VERSION')){
23-
define('INTEGRATION_ALEGRA_WC_SMP_VERSION', '0.0.14');
23+
define('INTEGRATION_ALEGRA_WC_SMP_VERSION', '0.0.15');
2424
}
2525

2626
add_action( 'plugins_loaded', 'integration_alegra_wc_smp_init');

lib/src/Client.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,23 @@ public function createSeller(array $data):array
393393
}
394394
}
395395

396+
public function getCostCenters($query = []):array
397+
{
398+
try {
399+
$response = $this->client()->get("cost-centers", [
400+
"headers" => [
401+
"Accept" => "application/json",
402+
"Authorization" => "Basic " . base64_encode("$this->user:$this->pass")
403+
],
404+
"query" => $query
405+
]);
406+
return self::responseJson($response->getBody()->getContents());
407+
}catch (RequestException $exception){
408+
$message = self::handleErrors($exception);
409+
throw new \Exception($message);
410+
}
411+
}
412+
396413
public function getSellers($query = []):array
397414
{
398415
try {

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Tags: commerce, e-commerce, commerce, WordPress ecommerce, store, sales, sell, s
55
Requires at least: 6.0
66
Tested up to: 6.9
77
Requires PHP: 8.1
8-
Stable tag: 0.0.14
8+
Stable tag: 0.0.15
99
WC requires at least: 9.6
1010
WC tested up to: 10.3
1111
License: GNU General Public License v3.0
@@ -189,6 +189,10 @@ Sí, el plugin incluye una opción de sincronización masiva de productos desde
189189

190190
== Changelog ==
191191

192+
= 0.0.15 =
193+
* Added support for Cost Centers (Centros de costo) in invoice generation
194+
* Added Cost Center configuration in settings
195+
192196
= 0.0.14 =
193197
* Add invoice settings for order and invoice status configuration
194198
* Refactor invoice column handling in WooCommerce admin orders

0 commit comments

Comments
 (0)