{"id":5539,"date":"2023-04-10T19:32:44","date_gmt":"2023-04-10T19:32:44","guid":{"rendered":"https:\/\/graphica.pe\/add-correlative-code-for-claims\/"},"modified":"2024-07-11T20:55:37","modified_gmt":"2024-07-11T20:55:37","slug":"add-correlative-code-for-claims","status":"publish","type":"post","link":"https:\/\/graphica.pe\/en\/add-correlative-code-for-claims\/","title":{"rendered":"Add correlative code for claims"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"5539\" class=\"elementor elementor-5539 elementor-1\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-229174cd elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"229174cd\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-72045687\" data-id=\"72045687\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-68299f1a elementor-widget elementor-widget-text-editor\" data-id=\"68299f1a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\n<p>We have a claim form (worked with Elementor) and we want each claim received to have a unique code.<\/p>\n<p><br>We will work with a correlative code such as R001, R002.<\/p>\n<ol>\n<li>Copy this code into the WordPress <em>function.php<\/em> file.<\/li>\n<li>In order to identify the form:\n<ol>\n<li>Add the ID<em>&#8220;form_name<\/em>&#8221; to the form.<\/li>\n<li>Add the name <em>&#8220;Claim Book&#8221;<\/em> to the form.<\/li>\n<\/ol>\n<\/li>\n<li>We must modify the prefix of our database. In this case we use <em>&#8220;CJf2B6_&#8221;<\/em> but usually you have something like <em>&#8220;wp_&#8221;<\/em>.<\/li>\n<li>Also in the same line we must modify the name of the database table that hosts our claims. In this case we are using the elementor submission so we use <em>&#8220;_e_submissions&#8221;<\/em> and <em>&#8220;_e_submissions_values&#8221;<\/em>.<\/li>\n<li>If you want to render the Claim code generated in any field of the Form, you must add the Field and give it the ID <em>&#8220;reclamos_id&#8221;<\/em>.<\/li>\n<\/ol>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f83a308 elementor-widget elementor-widget-code-highlight\" data-id=\"f83a308\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-twilight copy-to-clipboard \">\n\t\t\t<pre data-line=\"16,19\" class=\"highlight-height language-php line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-php\">\n\t\t\t\t\t<xmp>\/\/ Libro de Reclamaciones - C\u00f3digo \u00fanico secuencial\n\nadd_action( 'elementor_pro\/forms\/validation', 'project_libro_reclamaciones_codigo_unico', 10, 2 );\n\n\nfunction project_libro_reclamaciones_codigo_unico( $record, $handler ) {\n    global $wpdb;\n    \n    \/\/ Verificar que se env\u00ede desde el formulario del libro de reclamaciones.\n    $form_name = $record->get_form_settings( 'form_name' ); \n    if($form_name != 'Libro de reclamaciones'){\n        return;\n    }\n    \n    \/\/ Buscamos el \u00faltimo lead enviado\n    $fv_form = $wpdb->get_results(\"SELECT id FROM CJf2B6_e_submissions WHERE element_id = 'acdb477' ORDER BY id DESC LIMIT 1\");\n    \n    \/\/ Tomamos el c\u00f3digo\n    $fv_val  = $wpdb->get_results(\"SELECT value FROM CJf2B6_e_submissions_values WHERE submission_id = \". $fv_form[0]->id .\" AND `key` = 'reclamos_id'\");\n    \n    \/\/ Si es el primer lead, se crear el primer c\u00f3digo de la secuencia, sino, sumamos uno\n    if($fv_val){\n        $fv_id = (int)preg_replace('\/[^0-9]\/', '',$fv_val[0]->value);\n        \n        $reclamo_num = $fv_id + 1;\n    }else{\n        $reclamo_num = 1;\n    }\n        \n    \/\/ Agregamos el c\u00f3digo con el id aumentado, el LR puede variar seg\u00fan tu necesidad\n    $reclamo_id = 'LR-'.sprintf(\"%04d\", $reclamo_num);\n    \n    \/\/ Actualizamos el input hidden donde renderizamos el id del reclamo generado\n    $record->update_field('reclamos_id', 'value', $reclamo_id);\n    $record->update_field('reclamos_id', 'raw_value', $reclamo_id);\n}\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>We have a claim form (worked with Elementor) and we want each claim received to have a unique code. We will work with a correlative code such as R001, R002. Copy this code into the WordPress function.php file. In order to identify the form: Add the ID&#8220;form_name&#8221; to the form. Add the name &#8220;Claim Book&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-5539","post","type-post","status-publish","format-standard","hentry"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/posts\/5539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/comments?post=5539"}],"version-history":[{"count":0,"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/posts\/5539\/revisions"}],"wp:attachment":[{"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/media?parent=5539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/categories?post=5539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/graphica.pe\/en\/wp-json\/wp\/v2\/tags?post=5539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}