Sheets Data Validation In Colum "O" is updated when Colum "P" values are +7 - validation

I have in Colum "O", on a dropdown list of two values (Yes, No).
I got a scrip running that every time I tick it to "Yes", in Colum "P" I get a timestamp of todays date.
Now, what I'm looking for is, after 7 days of this timestamp, the Value in the dropdown list in Colum "O" goes back to "No", and while doing so, it clears out the timestamp in Colum "P".
This way I could restart the process, of clicking "Yes", get a new timestamp, and after 7 days, it resets itself.
I've been digging deep, but cant find anything helpful.
Regards!

Try this:
function onEdit(e) {
e.source.toast('Entry');
Logger.log(JSON.stringify(e));
var s = e.range.getSheet();
if (s.getName() == "Sheet0" && e.range.columnStart == 14) {
e.source.toast('Flag1');
let dt = new Date();
if (e.range.offset(0, 1).getValue() === '') {
e.range.offset(0, 1).setValue(dt);
}
let thv = new Date(dt.getFullYear(), dt.getMonth(), dt.getDate() - 7).valueOf();
s.getRange(1, 15, s.getLastRow()).getValues().flat().forEach((el, i) => {
if (new Date(el).valueOf() <= thv) {
s.getRange(i + 1,14,1,2).setValues([["No",""]]);
}
})
}
}

Related

How to check if month change?

I want to update all my depriciation cost each month for all items until 0
Example.
Depriciation has value of 111 . each month it should be depreciated until depriciation cost
reach 0 or less than
controller
all_item=assets::all();
foreach($all_item as $item)
{
//should i make static month to compare?
$month=Carbon::now()->format('m');
$update_item = assets::findOrFail($item->id);
$update_item->depriciation_cost = $item->depriciation - $item->depriciation_cost;
$update_item->update();
}
You can create a new column in the table to keep track of the last depreciation value updated like depreciation_updated_at (type: date) OR use created_at/updated_at column to get the last update month (if no other reason to update record).
Then simply use updated version of your code:
all_item=assets::all();
foreach($all_item as $item)
{
$month=Carbon::now()->format('m');
$depreciation_updated_at = createFromFormat('Y-m-d', $item->depreciation_updated_at); //or can use created_at/updated_at as said below
if ($depreciation_updated_at ->format('m') != $month) {
$update_item = assets::findOrFail($item->id);
$update_item->depriciation_cost = $item->depriciation - $item->depriciation_cost;
$update_item->update();
}
}
Hope it will do your task.

Carbon setTestNow function is not working

I am working on dates in Laravel. I have to set dates for patient future injections.
To keep it simple, let's suppose today is 13-03-2019 (Wednesday).
I created first date as:
$firstDate = Carbon::create(2019,03 ,18, 12); // The day is Monday
// set date
Carbon::setTestNow($firstDate);
Now I want the next two appointments should be on Wednesday and Friday. So I again set the dates as follow:
// set second date
$secondDate = new Carbon('Wednesday');
Carbon::setTestNow($secondDate);
// set thirdDate
$thirdDate = new Carbon('Friday');
Carbon::setTestNow($thirdDate);
According to above example the output should be:
2019-03-18
2019-03-20
2019-03-22
But the problem is that it outputs the first set date correct but print the 2nd and 3rd date wrong as it considers 'Wednesday' of next week as today's date.
So the Output print as:
2019-03-18
2019-03-13
2019-03-14
I have spent a lot of time on it, I would appreciate if anyone of you people could help me in this.
I would appreciate if anyone guides me where I am going wrong.
Thanks.
As the setTestNow() function was not working for 2nd and third date/days, so I first get all three required days then convert them to 'dayOfWeek' which returns day number (Sunday 0, Monday 1 and so on...). I subtracted the first day from second and third day and then finally add these days to the date that i get from the datepicker.
// set the start date
if( $visitstart_date != null && $visitstart_date != '') {
Carbon::setTestNow($visitstart_date);
} else {
Carbon::setTestNow();
}
if($perweek_visit1_day != '')
{
//Get first selected day number
$firstDay = Carbon::parse($perweek_visit1_day)->dayOfWeek;
$perweek_visit1_dayDate = Carbon::now();
}
if($perweek_visit2_day != '')
{
//Get second day numer
$secondDay = Carbon::parse($perweek_visit2_day)->dayOfWeek - $firstDay;
$perweek_visit2_dayDate = Carbon::now()->addDays($secondDay);
}
if($perweek_visit3_day != '')
{
//Get third day number
$thirdDay = Carbon::parse($perweek_visit3_day)->dayOfWeek - $firstDay;
$perweek_visit3_dayDate = Carbon::now()->addDays($thirdDay);
}

Datatable count

I am using the DataTables jQuery plugin to display data from the database.
Currently I am using the example of Row Grouping to display the days per week.
I am working at this for a week now to also display an row at the bottom of the week to count the hours of that week but it seems to be nearly to impossible with this plugin to achieve that goal. Is there anybody who could advise me if this can be done and how.
Here is my code:
var api = this.api(),data;
var rows = api.rows({ page:'current' }).nodes();
var last = null;
total = new Array();
api.column(weekColumn, { page:'current' }).data().each(function(group, i) {
group_assoc = group.replace(' ',"_");
if (typeof total[group_assoc] != 'undefined') {
total[group_assoc]=total[group_assoc]+api.column(5).data()[i];
} else {
total[group_assoc]=api.column(5).data()[i];
}
if (last !== group) {
$(rows).eq( i ).before('<tr class="group" style="background-color:#3ea5ce;color:#ffffff;"><td colspan="5">{{ trans('admin.worktime.field.week') }} '+group+'</td><td colspan="3" class="'+group_assoc+'"></td></tr>');
last = group;
}
});
for (var key in total) {
$("." + key).html(total[key]);
}
Currently, it is been outputted as 09:3907:0008:0107:5207:28 instead of been counted as a total. How can I solve this?
I think you are trying to sum time values, but they are treated as strings and concatenated.
This post describes how to first make integer values of these time strings first. Calculate the sum of the integers and convert that back to a time.

KendoUI scheduler Week view :-how to get date of start of week

I am using KendoUI scheduler in my application. is there any way to get the start of week when the selected view is week.
Yes. Use the navigate event to catch current date and get the start of week by manipulating the retrieved date. i.e.
navigate: function (e) {
if (e.view.toLowerCase() === "week") {
GetStartDateOfWeek(e.date);
}
}
function GetStartDateOfWeek(d) {
d = new Date(d);
var day = d.getDay(),
diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday
var startOfWeek = new Date(d.setDate(diff));
}
Hope it helps!
Reference: JavaScript - get the first day of the week from current date

LINQ - how to get next three business days excluding dates in table?

I need to find the next three available business days for a scheduling application. What is available depends upon excluded dates in a table. So...as long as the date is not in my table and not a Saturday or Sunday, I want the next three. I'd like to find an efficient way of doing this.
I need to return a List<DateTime>. The table is simple - ExcludedDates has an ID and a DateTime with the excluded date.
I'd like to have a single LINQ query expression but can't figure it out...thanks to all in advance and I apologize if this is trivial or obvious - it isn't to me.
Try this...
DateTime start = DateTime.Now.Date;
var result = Enumerable.Range(1, 10) // make this '10' higher if necessary (I assume you only exclude non-workingdays like Christmas and Easter)
.Select(offset => start.AddDays(offset))
.Where(date => !( date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek== DayOfWeek.Sunday))
.Where(d=> !exceptionTable.Any(date => date == d))
.Take(3).ToList();
List<DateTime> result = (from i in Enumerable.Range(1, excludeTable.Rows.Count + 6)
let date = inputDate.AddDays(i)
where date.DayOfWeek != DayOfWeek.Saturday &&
date.DayOfWeek != DayOfWeek.Sunday &&
!excludeTable.Rows.Cast<DataRow>().Select(r => (DateTime) r["ExcludeDate"]).Contains(date)
select date).Take(3).ToList();
excludeTable.Rows.Count + 6 is to cover the worst case where you skip over every thing in the excludeTable and then you have to skip over another weekend.
This assumes that a month will be reasonable depending on your excluded dates.
DateTime date = DateTime.Today;
// first generate all dates in the month of 'date'
var dates = Enumerable.Range(1, DateTime.DaysInMonth(date.Year, date.Month)).Select(n => new DateTime(date.Year, date.Month, n));
// then filter the only the start of weeks
var results = (from d in dates
where d.DayOfWeek != DayOfWeek.Saturday && d.DayOfWeek != DayOfWeek.Saturday && !excludes.Any(i => i.DateTime.Date == d.Date) && date < d
select d).Take(3);
var excludedList = new List<long>() { DateTime.Parse("2011-07-27").Ticks };
var week = new List<long>(){
DateTime.Now.Date.Ticks,
DateTime.Now.Date.AddDays(1).Ticks,
DateTime.Now.Date.AddDays(2).Ticks,
DateTime.Now.Date.AddDays(3).Ticks,
DateTime.Now.Date.AddDays(4).Ticks,
DateTime.Now.Date.AddDays(5).Ticks,
DateTime.Now.Date.AddDays(6).Ticks,
DateTime.Now.Date.AddDays(7).Ticks,
DateTime.Now.Date.AddDays(8).Ticks
};
var available = (from d in week.Except(excludedList)
where new DateTime(d).DayOfWeek != DayOfWeek.Saturday && new DateTime(d).DayOfWeek != DayOfWeek.Sunday
select new DateTime(d)).Take(3);
foreach (var a in available)
Console.WriteLine(a.ToString());

Resources