pub fn amazon_single_order_id_process(
    rrc: &mut RootRenderingComponent,
    order_id: &str,
    vdom_weak: dodrio::VdomWeak,
) {
    //ricevuta and ddt are created in the same time.
    //the request body must be reset to the template for replace
    reqbodymod::create_reqbody_ricevute_nuovo(rrc);

    let mut total = 0.0;
    let mut total_qty = 0.0;
    let mut line_count = 0;
    let vec_rec_clone = rrc.vec_rec.clone();
    for record in vec_rec_clone.iter() {
        for rec_fieldx in record {
            //this first loop only finds the right record
            if rec_fieldx.0 == "order-id" && rec_fieldx.1.clone() == order_id {
                //this is the right record.
                //there is at least one product, but prepare the space for the next one. This will be removed at the end.
                rrc.reqbody = rrc.reqbody.replace(
                    "articolo-template",
                    format!("{} \n articolo-template", reqbodymod::articolo_template()).as_str(),
                );

                //loop all the fields and replace. The second, third,... time there will be only articolo-template to replace.
                //All else is already replaced.
                for rec_field in record {
                    //this works only if the field names in CSV are really unique and unmistakable
                    log1("replace");
                    log1(rec_field.0.as_str());
                    log1(rec_field.1.as_str());
                    let field_name = rec_field.0;
                    //if there is a sign " escape it for json to \"
                    let mut field_value = rec_field.1.replace(r#"""#, r#"\""#);

                    //from sku get product-name from webserver, but it is asynchronous
                    //change placeholder from product-name to product-name1, 2,...
                    //so there is uniquness for async
                    if field_name == "sku" {
                        let v2 = vdom_weak.clone();
                        replace_sku_name(line_count, rrc, v2, field_value.to_string());
                    }

                    //convert date from 2019-07-04T11:51:26+00:00 to 23/07/2019
                    if field_name == "purchase-date" || field_name == "payments-date" {
                        field_value = format!(
                            "{}/{}/{}",
                            unwrap!(field_value.get(8..10)).to_string(),
                            unwrap!(field_value.get(5..7)).to_string(),
                            unwrap!(field_value.get(0..4)).to_string()
                        );

                        //the ricevuta and ddt have today-date
                        let today = js_sys::Date::new_0();

                        let dd = today.get_date();
                        #[allow(clippy::integer_arithmetic)]
                        let mm = today.get_month() + 1; //January is 0!
                        let yyyy = today.get_full_year();

                        let today_date = format!("{:02}/{:02}/{}", dd, mm, yyyy);
                        rrc.reqbody = rrc.reqbody.replace("today-date", today_date.as_str());
                    }
                    //find the country name in Italian from ISO code
                    if field_name == "ship-country" {
                        replace_ship_county_dependent(rrc, field_value.to_string(), record);
                    }
                    if field_name == "quantity-purchased" {
                        //from string to decimal
                        let f64_quantity_purchased: f64 = unwrap!(field_value.parse());
                        log1(&format!("{}", f64_quantity_purchased));
                        total_qty += f64_quantity_purchased;
                    }
                    if field_name == "item-price" {
                        //from string to decimal
                        let f64_item_price: f64 = unwrap!(field_value.parse());
                        log1(&format!("{}", f64_item_price));
                        total += f64_item_price;
                    }
                    if field_name == "shipping-price" {
                        //from string to decimal
                        let f64_shipping_price: f64 = unwrap!(field_value.parse());
                        log1(&format!("{}", f64_shipping_price));
                        //only the first time
                        if line_count == 0 {
                            total += f64_shipping_price;
                        }
                    }
                    rrc.reqbody = rrc.reqbody.replace(field_name.as_str(), &field_value);
                }
                line_count += 1;
            }
        }
    }
    log1(&format!("total {}", total));
    //the total
    rrc.reqbody = rrc
        .reqbody
        .replace("total-importo", format!("{:.2}", total).as_str());
    //total quantity
    rrc.reqbody = rrc
        .reqbody
        .replace("total-quantity", format!("{:.0}", total_qty).as_str());

    //remove the articolo-template
    rrc.reqbody = rrc.reqbody.replace("articolo-template", "");
}
/// process one order-id and modify request json
process one order-id and modify request json
process one order - id and modify request json
pub fn amazon_single_order_id_process(
    rrc: &mut RootRenderingComponent,
    order_id: &str,
    vdom_weak: dodrio::VdomWeak,
) {
    //ricevuta and ddt are created in the same time.
    //the request body must be reset to the template for replace
    reqbodymod::create_reqbody_ricevute_nuovo(rrc);
    let mut total = 0.0;
    let mut total_qty = 0.0;
    let mut line_count = 0;
    let vec_rec_clone = rrc.vec_rec.clone();
    for record in vec_rec_clone.iter() {
        for rec_fieldx in record {
            //this first loop only finds the right record
            if rec_fieldx.0 == "order-id" && rec_fieldx.1.clone() == order_id {
                //this is the right record.
                //there is at least one product, but prepare the space for the next one. This will be removed at the end.
                rrc.reqbody = rrc.reqbody.replace(
                    "articolo-template",
                    format!("{} \n articolo-template", reqbodymod::articolo_template()).as_str(),
                );
                //loop all the fields and replace. The second, third,... time there will be only articolo-template to replace.
                //All else is already replaced.
                for rec_field in record {
                    //this works only if the field names in CSV are really unique and unmistakable
                    log1("replace");
                    log1(rec_field.0.as_str());
                    log1(rec_field.1.as_str());
                    let field_name = rec_field.0;
                    //if there is a sign " escape it for json to \"
                    let mut field_value = rec_field.1.replace(r#"""#, r#"\""#);
                    //from sku get product-name from webserver, but it is asynchronous
                    //change placeholder from product-name to product-name1, 2,...
                    //so there is uniquness for async
                    if field_name == "sku" {
                        let v2 = vdom_weak.clone();
                        replace_sku_name(line_count, rrc, v2, field_value.to_string());
                    }
                    //convert date from 2019-07-04T11:51:26+00:00 to 23/07/2019
                    if field_name == "purchase-date" || field_name == "payments-date" {
                        field_value = format!(
                            "{}/{}/{}",
                            unwrap!(field_value.get(8..10)).to_string(),
                            unwrap!(field_value.get(5..7)).to_string(),
                            unwrap!(field_value.get(0..4)).to_string()
                        );
                        //the ricevuta and ddt have today-date
                        let today = js_sys::Date::new_0();
                        let dd = today.get_date();
                        #[allow(clippy::integer_arithmetic)]
                        let mm = today.get_month() + 1; //January is 0!
                        let yyyy = today.get_full_year();
                        let today_date = format!("{:02}/{:02}/{}", dd, mm, yyyy);
                        rrc.reqbody = rrc.reqbody.replace("today-date", today_date.as_str());
                    }
                    //find the country name in Italian from ISO code
                    if field_name == "ship-country" {
                        replace_ship_county_dependent(rrc, field_value.to_string(), record);
                    }
                    if field_name == "quantity-purchased" {
                        //from string to decimal
                        let f64_quantity_purchased: f64 = unwrap!(field_value.parse());
                        log1(&format!("{}", f64_quantity_purchased));
                        total_qty += f64_quantity_purchased;
                    }
                    if field_name == "item-price" {
                        //from string to decimal
                        let f64_item_price: f64 = unwrap!(field_value.parse());
                        log1(&format!("{}", f64_item_price));
                        total += f64_item_price;
                    }
                    if field_name == "shipping-price" {
                        //from string to decimal
                        let f64_shipping_price: f64 = unwrap!(field_value.parse());
                        log1(&format!("{}", f64_shipping_price));
                        //only the first time
                        if line_count == 0 {
                            total += f64_shipping_price;
                        }
                    }
                    rrc.reqbody = rrc.reqbody.replace(field_name.as_str(), &field_value);
                }
                line_count += 1;
            }
        }
    }
    log1(&format!("total {}", total));
    //the total
    rrc.reqbody = rrc
        .reqbody
        .replace("total-importo", format!("{:.2}", total).as_str());
    //total quantity
    rrc.reqbody = rrc
        .reqbody
        .replace("total-quantity", format!("{:.0}", total_qty).as_str());
    //remove the articolo-template
    rrc.reqbody = rrc.reqbody.replace("articolo-template", "");
}
pub fn amazon_single_order_id_process ( rrc : & mut RootRenderingComponent , order_id : & str , vdom_weak : dodrio :: VdomWeak , ) { //ricevuta and ddt are created in the same time. //the request body must be reset to the template for replace reqbodymod :: create_reqbody_ricevute_nuovo ( rrc ) ; let mut total = 0.0 ; let mut total_qty = 0.0 ; let mut line_count = 0 ; let vec_rec_clone = rrc . vec_rec . clone ( ) ; for record in vec_rec_clone . iter ( ) { for rec_fieldx in record { //this first loop only finds the right record if rec_fieldx . 0 == " " && rec_fieldx . 1 . clone ( ) == order_id { //this is the right record. //there is at least one product, but prepare the space for the next one. This will be removed at the end. rrc . reqbody = rrc . reqbody . replace ( " " , format ! ( " \n " reqbodymod articolo_template ( ) ) . as_str ( ) , ) ; //loop all the fields and replace. The second, third,... time there will be only articolo-template to replace. //All else is already replaced. for rec_field in record { //this works only if the field names in CSV are really unique and unmistakable log1 ( " " ) ; log1 ( rec_field . 0 . as_str ( ) ) ; log1 ( rec_field . 1 . as_str ( ) ) ; let field_name = rec_field . 0 ; //if there is a sign " escape it for json to \" let mut field_value = rec_field . 1 . replace ( r#"""# , r#"\""# ) ; //from sku get product-name from webserver, but it is asynchronous //change placeholder from product-name to product-name1, 2,... //so there is uniquness for async if field_name == " " { let v2 = vdom_weak . clone ( ) ; replace_sku_name ( line_count , rrc , v2 , field_value . to_string ( ) ) ; } //convert date from 2019-07-04T11:51:26+00:00 to 23/07/2019 if field_name == " " || field_name == " " { field_value = format ! ( " " unwrap ( field_value get ( 8 10 ) ) to_string ( ) unwrap ( field_value get ( 5 7 ) ) to_string ( ) unwrap ( field_value get ( 0 4 ) ) to_string ( ) ) ; //the ricevuta and ddt have today-date let today = js_sys :: Date :: new_0 ( ) ; let dd = today . get_date ( ) ; # [ allow ( clippy integer_arithmetic ) ] let mm = today . get_month ( ) + 1 ; //January is 0! let yyyy = today . get_full_year ( ) ; let today_date = format ! ( " " dd mm yyyy ) ; rrc . reqbody = rrc . reqbody . replace ( " " , today_date . as_str ( ) ) ; } //find the country name in Italian from ISO code if field_name == " " { replace_ship_county_dependent ( rrc , field_value . to_string ( ) , record ) ; } if field_name == " " { //from string to decimal let f64_quantity_purchased : f64 = unwrap ! ( field_value parse ( ) ) ; log1 ( & format ! ( " " f64_quantity_purchased ) ) ; total_qty += f64_quantity_purchased ; } if field_name == " " { //from string to decimal let f64_item_price : f64 = unwrap ! ( field_value parse ( ) ) ; log1 ( & format ! ( " " f64_item_price ) ) ; total += f64_item_price ; } if field_name == " " { //from string to decimal let f64_shipping_price : f64 = unwrap ! ( field_value parse ( ) ) ; log1 ( & format ! ( " " f64_shipping_price ) ) ; //only the first time if line_count == 0 { total += f64_shipping_price ; } } rrc . reqbody = rrc . reqbody . replace ( field_name . as_str ( ) , & field_value ) ; } line_count += 1 ; } } } log1 ( & format ! ( " " total ) ) ; //the total rrc . reqbody = rrc . reqbody . replace ( " " , format ! ( " " total ) . as_str ( ) ) ; //total quantity rrc . reqbody = rrc . reqbody . replace ( " " , format ! ( " " total_qty ) . as_str ( ) ) ; //remove the articolo-template rrc . reqbody = rrc . reqbody . replace ( " " , " " ) ; }
process one order-id and modify request json
process one order - id and modify request json
rrc
&mut RootRenderingComponent
order_id
&str
vdom_weak
dodrio::VdomWeak